use ivy java project in maven? - java

I have a big maven project with many subprojects that are also maven based.
I started using Red5, and red5 creates an ivy based project. I need to add that project to the dependencies.
list files of project main directory:
build.properties build.xml ivy.xml ivysettings.xml lib readme.txt src www
how can I add this project as one of the maven project dependencies ?
using Java with Maven 3.0.4
thanks!
Kfir

Interesting... A lib directory in an Ivy project.
You can modify the build.xml to create one more target that calls the <ivy:makepom/> target. Just make sure that <ivy:resolve> is called first. This will create a small piece of the pom.xml file you need.
As for the rest. What's that technical term? Oh yeah, you're screwed.
The problem is that Ant and Maven have two completely different build philosophies. In Ant, you write a build.xml script that describes what you want to build and how you want to build it. In Maven, you describe your project via a pom.xml file, and Maven does all the build processing for you.
This isn't an issue of whether or not Whether Ant or Maven is the force of all that's good in the world and the other is only for luzers Apple Fanboys. This is a case of manually converting a pre-existing project into Maven.
You'll have to go through your build.xml and figure out everything it is doing. Then, you need to convert this over to a Maven pom.xml file. There's no way to automate this. Even worse, Red5 isn't setup like a Maven project, so you'll either have to move all the files around, or go into archaic pom.xml configuration hell trying to override how Maven assumes the build is suppose to take place. This can take days, even weeks to get right. And, in the end, you end up with a project you don't control that if you want to update will have to be done all over again from scratch.
Trust me, I did this before for another job where the System Architect decided that Maven was better than Ant, and all of our projects must be converted from Ant to Maven. And, who got stuck with this task? Not the developers who were too busy with other tasks, but I the Configuration Manager.
And, in the end, you will have a project you don't control that if you want to update will have to be done all over again from scratch.
There is an alternative: Ignore it.
Does it really matter if Red5 is an Ivy project? What do you need from this Red5 project anyway? Do you need that red5.jar or the distribution that gets built.
If you need the distribution, let it remain as an Ivy project. Simply set the ivysettings.xml to point to your Maven repository and let it know that it's in Maven 2 format. Ivy will have no problems getting stuff out of that. So what if it's Ivy?
If you just need that red5.jar file in your other Maven project, you can simply use the <ivy:makepom/> task to generate a pom.xml file for you. Then use mvn deploy:deploy-file to deploy that jar into your Maven repository:
$ mvn deploy:deploy-file -Dfile=red5.jar \
-DpomFile=pom.xml \
-DrepositoryId=$repoId \
-Durl=$url
Now, your red5.jar is in your Maven repository as a fully transitive downloading jar. If you really, really want to get fancy, you can embed the generated pom.xml file into the jar itself, so it is self referential just like Maven jars are. That will take about 30 minutes of hacking the current build.xml file. (Or, if your jar doesn't have to have the pom.xml embedded in it, a separate Ant file that just builds the pom.xml you need, and maybe even deploys it into your Maven repository for you. That way, if the project gets updated, you don't have to worry about the build.xml file being updated.

I've not used it myself, but I know Ivy has a task which can convert an ivy file to a maven pom. I'd explore an option where my CI environment runs that task to generate a pom after a successful build, and then get my maven project to look at the CI's latest artifacts for the jar and pom. You could skip the CI environment as well, and have maven resolve artifacts from the local file system.

I don't think you're going to get away without creating a JAR. Maven's whole dependency philosophy is built around JAR files in a repository - when one maven project depends on another the way it works is that the dependent project builds its JAR and puts it in the local repository, then the main project depends on it from there.
That said, you can fairly easily automate this using a combination of <ivy:makepom> and the Maven Ant Tasks. The idea is to make the Ivy project build its JAR and push that to the local Maven repository as part of every build, so it is immediately available for the maven projects to depend on.
<jar destfile="project.jar">
<fileset dir="classes" />
</jar>
<ivy:makepom ivyfile="ivy.xml" pomfile="project.pom" conf="default,runtime">
<mapping conf="default" scope="compile"/>
<mapping conf="runtime" scope="runtime"/>
</ivy:makepom>
<artifact:pom id="project.pom" file="project.pom" />
<artifact:install file="project.jar" pomRefId="project.pom" />
Make sure your Ivy project has a version number that ends with -SNAPSHOT in its ivy.xml.

Related

Deploy Ant project into Maven repository

I am new using Maven and I need to upload some libraries from an Ant project. To develop this task I have one folder that contains a lot of "pom.xml" files that refers to the jar that I would like to add to my project in Eclipse using Maven, and another xml file that is the Ant project itself.
All ideas are welcome. Thanks!
Unfortunately no good tools exists for Ant to Maven migration. You will need going step by step from module to module do so:
Enable maven nature on each project.
Resolve maven dependency by hand.
Deploy artifact into local or remote repository.
Pay your attention on version numbers of libraries. Make sure the md5 hash or sha2 hash of library in ant project and the library received in maven after adding dependency is exactly same. Otherwise you will definitely get some non traceable errors if not during testing but after deployment to prod.

How to include non-maven Netbeans modules in Maven application?

I found the opposite version of this question here: How to include maven-based project into my non-maven project but didn't give me any light on the issue.
I know the long road to do this:
Mavenize the module in question.
Add as a dependency.
But this only works if:
You have access to the source of the original module.
The project is well structured as this would complicate mavenizitation.
All this seems unnecessary, there should be a better way. Any idea?
if you have an ant-based module you want to consume in your maven based platform, you will need these artifacts.
module .jar file
module's .nbm file
without these, you are out of luck.
If you have them, create a basic pom file, invent the Maven GAV for the module and use mvn install:install-file or mvn deploy:deploy file to upload the pom, jar and nbm file to a place where it can be consumed by the maven build.

Building complex project with Ant

I have an Eclipse project that depends on several other projects from the same workspace. I know hot to create a simple Ant build script for a single independent Java project, but how to tell Ant to integrate all those project into my main JAR file so my dependent program can work?
In Ant, the simplest way is to explicitly enumerate those other projects and include them in the jar target. Something like:
<path id="all-projects">
<fileset dir="../my.other.project" includes="**/*class">
</path>
One solution : Create a master project and put all the projects into it and have a single build.xml.
Another option : Create a master project but leave everything at the same level (do not place project-components inside the project folder) Then arrange your build script to refer to the other projects via relative paths. Note that with some build tools this is not even necessary as they will look at their repository.
While you can munge together a solution with Ant, Apache Maven is a better solution for managing dependencies than Ant. If you don't want to go with a full blown Maven lifecycle management project, you can also look at using a Nexus repository to store your artifacts, and include Apache Ivy in your Ant build scripts to perform dependency management.
Ivy or Maven will provide a better, more manageable dependency management strategy which is likely to be easier to integrate into a team than anything you will be able to assemble on your own.

Maven: antrun plugin builds JAR file -> How can i install/deploy it in my repository?

I am in the middle of an Ant -> Maven migration project and I have a question (I'm not really a Maven expert), since I'm stuck at a particular point:
Within one of my pom.xml files I have to use the maven-antrun-plugin to call an external ANT file, which builds a jar file and puts it in a temporary folder. There is no alternative to this call. Everything is working fine - the ant script works as it should, but how can I "package" this jar in the usual Maven workflow?
I know that I could manually call the mvn install:install-file, but isn't there a possibility to configure my pom.xml in a way that the above generated jar file IS actually the artifact of that pom.xml?
you use the build helper maven plugin's attach artifact goal to attach your extra *.jar to the maven module that triggered its creation.
since having a single maven module produce more than one artifact is generally a bad idea it would be best if you isolate this in a maven module of type pom so that this would be its only artifact

Link maven dependencies on non maven project

I have two projects in Eclipse, the first project depends on maven, the second project which dependent on the first one does NOT depend on maven.
The first project downloads external libraries like jar files and natives to the .m2 maven folder. However the second project gives a ClassNotFoundException since it cant find the jar files and the native files from the first project.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I would appreciate any help.
In your Maven project, use Assembly plugin to create an Uber-jar that contains the project build artifact and all its dependencies (mvn assembly:assembly -DdescriptorId=jar-with-dependencies). Then, reference that from project #2, either with a relative path or by using an ant build task to copy it into your other project's lib directory (assuming you have such a directory). Also, although it's frowned upon, you could configure the assembly plugin so that your Uber jar artifact always has the same finalName.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I don't think so.
But maybe you could create a 3rd project (which is a Maven project) that depends on the first one, and on the JAR (or whatever) file created by the 2nd one as a non-repository dependency.
Having said that, anything you do is going to be a bit of a hack. You'd be better of either turning the 2nd project into a proper Maven project, or creating a custom build script that manually pulls the 2nd project's dependencies from somewhere. (I think that Ivy could help you with that ... assuming you use Ant in the 2nd project.)

Categories