Maven Ant Tasks: Install artifact (artifact:install) with unknown target filename - ant

In my Ant script, i'm using the Maven Ant tasks to install an artifact to the local repository, like this:
<target name="installProject">
<artifact:pom id="mypom" file="${user.dir}/pom.xml" />
<artifact:install file="target/myproject-1.0.jar">
<pom refid="mypom"/>
</artifact:install>
</target>
What i don't like about this approach is that i have to define the name of the Jar I want to install explicitely: target/myproject-1.0.jar But what if the name of that Jar changes? I want to have a more generic approach. How can i let Maven Ant Tasks install all artifacts that Maven would also install when running mvn clean install in the same dir on commandline (where I DON'T have to provide which Jar i want to install)?
(yes, i could also just call Maven with <exec executable="mvn" ...>, but I think it's cleaner to use Maven Ant Tasks for this)

Nobody knows what your build.xml produces so you need to pass desired artifact names to ant. It can be done through project.groupId, project.artifactId, project.version properties that should be available in your antrun element.
Then after you build.xml worked. You can use attachartifact ant task to attach your artifacts to maven. I.E.
<attachartifact file="${project.build.directory}/${project.artifactId}-${project.version}.jar" type="jar"/>
After that when you performing maven install it install your ant artifacts.

Related

Download dependencies from Ivy.xml

I have an ant project with ivy dependencies in it. Unfortunately my Intelij IDEA does not understend ivy dependencies. But ant builds project well. I want to download all dependencies to one folder and add jars explicitly to project.
How can i download all dependencies automatically?
As described here http://ant.apache.org/ivy/history/latest-milestone/ant.html
During ant build ivy dependencies downloads to "cache". If i'll found this cache path i can took jars from there.
Look at what ant is doing. If its a well written ant script you'll find (do an ant -p -v) targets specifically for retrieving the ivy dependencies. Also you may inspect the build.xml and watch out for retrieve tasks probably in the ivy namespace.

ant/Jenkins: move doesn't support the "quiet" attribute

My build script executes:
<move todir="gen" overwrite="true" quiet="true">
<fileset dir="gen">
<include name="**/BuildConfig.java.new"/>
</fileset>
<globmapper from="*.java.new" to="*.java"/>
</move>
I get the error:
move doesn't support the "quiet" attribute
I have ant 1.8.4 installed on my iMac. My ant plugin in Jenkins is 1.2. Jenkins ver. 1.505.
I have tried to change the PATH when starting Jenkins, so it includes my command line ant.
However it seems that Jenkins does not support ant 1.8.3? ant 1.8.3 is the version where the "move quiet" was added.
Any thoughts how I can solve this? Is it related to command line ant or plugin ant or my build script?
Thanks!
Assuming that you're running Jenkins on your iMac, go to [http://yourjenkins/configure] and add an Ant installation that points to your Ant 1.8.4 directory. Then, in the Ant build step of your Jenkins job configuration, specify that version of Ant and things should start working.
If your Jenkins server is on a different machine, repeat the instructions but install Ant 1.8.4 on the Jenkins server, or use the "Install automatically" option to install Ant on demand.
I solved it by:
In Jenkins setup, set a tool location for ant
Now in my build job a new selection appeared: Ant Version
My ant on my mac:
ant -v
Apache Ant(TM) version 1.8.4 compiled on May 22 2012

Can we use pom.xml into ANT

I know that, we can very well use ANT and Maven together to build the project.We can run ANT scripts through Maven's POM.xml. But my question is can we run pom.xml through ANT's build.xml ?
i.e. can we create maven build from build.xml
Yes, using maven ant tasks.
The page lists out multiple maven tasks which can be integrated into an ant build script, thus combining the features of both. To take an example, there is the mvn task, which as documented can do a full maven build from ant.
<artifact:mvn mavenHome="/path/to/maven-3.0.x">
<arg value="install"/>
</artifact:mvn>
Besides this, there are
Dependencies task
Install and Deploy tasks
Pom task
each described with examples.
Maven and ANT are very different build tools. In ANT you write all the logic yourself, whereas a standard build process is "baked in" with Maven.
The POM file contains no logic, instead it contains a series of declarations about your project.
If you understand well how Maven works, it is theoretically possible to take a POM and generate an ANT build that emulates the behaviour of the Maven build. I'm not aware of any solution which can easily convert in the other direction, mainly because ANT is missing Maven functionality, such as dependency management.
Instead of trying to convert an ANT build into Maven, I'd recommend that you keep your existing build logic and delegate the management of your classpath to the ivy or Maven ANT tasks. These tools also provide tasks to publish your build output to a Maven repository, enabling your project to share with other projects using Maven.
Finally, I'm an ivy advocate and wrote an ant2ivy script which can assist in upgrade process. It creates an initial set of configuration files for downloading your projects dependencies from the Maven central repository.

Maven run ant builds in subdirectories

I have multiple JavaFX 2.0 apps (built with the default ant scripts generated by netbeans 7.0) which I want to be wrapped up into a war by a maven pom in the parent directory.
The war-building pom has lots of ant tasks in the compile phase that look like this:
<ant antfile="FXapplication1/build.xml" target="jar"/>
But when I go to run 'mvn compile', I get this error from ant:
"C:\path\to\warbuilder\FXapplication1\nbproject\build-impl.xml:209: Must set src.dir"
The ant script builds fine when explicitly called inside its own directory, so I'm assuming that the problem is that it's looking in the war builder's local directory for its source files, rather than looking for them relative to the build.xml. Is there a way to specify a working path for a given ant task?
Try making the JavaFX apps modules of the warbuilder app, each with their own pom which executes <ant antfile="build.xml" target="jar"/>,
rather than running <ant antfile="FXapplication1/build.xml" target="jar"/> from the parent.
The parent should list the children as modules, they will then be executed as part of the parent build process.

How can I build Maven dependencies from Ant Java classpath?

Using Maven Ant Tasks, I see lots of examples that build Ant classpath from Maven dependencies, but what about the other way round?
I have a carefully tuned Ant project that builds the Java task classpath from all the jars in my lib directory. How can I use Maven-Ant-tasks to use my classpath to build Maven dependencies?
I would rather not do each jar file individually (my last resort).
Is there a better way?
If you're working on converting from Ant to Maven, just bite the bullet and write out your <dependencies> section to match your ant classpath. You only have to do it once, and you'll thank yourself many times over.

Resources