We are using Maven in combination with an Ant build.xml file for our buids.
The maven-antrun-plugin looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<!-- Version 1.8 uses Ant 1.9.4 -->
<version>1.8</version>
<executions>
<execution>
<id>Compile sources</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${temp.dir}"/>
<mkdir dir="${dist.dir}"/>
<exec dir="${project.basedir}" executable="${ant.exec}" failonerror="true">
<arg
line="-f xlatedb.ant.xml -DDLC ${dlc} -lib ${lib.dir}
-Dtarget.dir ${target.dir}
-Ddist.dir ${dist.dir}
-Dtemp.dir ${temp.dir}
-Dproject.version ${project.version} "/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
The maven-antrun-plugin uses Ant 1.9.4 internally. Is there a way to replace the dependency to ${ant.exec} with a call to that internal ant jar?
Now we pass the ant.exec to the mvn command. Using the ant task doesn't work because we also need to pass the -lib to ant. (the lib folder contains all of the downloaded dependencies).
The advantage of using this ant.exec approach is that we can use ant 1.10.5. I could however specify ant 1.10.5 in the dependencies and get that jar downloaded to the lib folder... But instead of starting the ant.bat file I would need a way to launch ant with that 1.10.5 jar.
You could call ant main class through the exec:java
goal
pom.xml
<properties>
<target.dir>theTargetDirectory</target.dir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.apache.tools.ant.launch.Launcher</mainClass>
<arguments>-f,xlatedb.ant.xml</arguments>
<systemProperties>
<systemProperty>
<key>target.dir</key>
<value>${target.dir}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
xlatedb.ant.xml
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
<echo>${target.dir}</echo>
</target>
</project>
mvn compile
Output:
--- exec-maven-plugin:1.6.0:java (default) @ stack-55711525-maven-antexec ---
Buildfile: /xyz/project/xlatedb.ant.xml
print-version:
[echo] Apache Ant(TM) version 1.10.5 compiled on July 10 2018
[echo] theTargetDirectory
BUILD SUCCESSFUL
Total time: 0 seconds
NOTE: If you want to make maven classpath available to ant during jar
, I guess you can run copy-dependencies
plugin early enough in the lifecycle, and then provide the dependencies output directory as classpath to ant.
e.g.
<path id="class.path">
<fileset dir="target">
<include name="copied-dependencies-dir/*.jar" />
</fileset>
</path>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With