我们将Maven与Ant build.xml文件结合使用来创建buids。
maven-antrun-plugin如下所示:
<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>maven-antrun-plugin在内部使用Ant 1.9.4。有没有办法将对${ant.exec}的依赖替换为对该内部ant jar的调用?
现在我们将ant.exec传递给mvn命令。使用ant任务不起作用,因为我们还需要将-lib传递给ant。( lib文件夹包含所有下载的依赖项)。
使用这种ant.exec方法的好处是我们可以使用ant 1.10.5。但是,我可以在依赖项中指定ant 1.10.5,并将该jar下载到lib文件夹……但是,我不需要启动ant.bat文件,而是需要一种使用1.10.5JAR启动ant的方法。
发布于 2019-04-23 22:57:52
您可以通过exec:java目标调用ant主类
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输出:
- exec-maven-plugin:1.6.0:java (默认)@ stack-55711525-maven-antexec
构建文件: /xyz/project/xlatedb.ant.xml
打印版本:
_[echo] Apache Ant(TM) version 1.10.5 compiled on July 10 2018_ _[echo] theTargetDirectory_构建成功
总时间:0秒
注意:如果你想在jar期间让maven类路径对ant可用,我想你可以在生命周期中尽早运行copy-dependencies插件,然后将依赖输出目录作为类路径提供给ant。
例如:
<path id="class.path">
<fileset dir="target">
<include name="copied-dependencies-dir/*.jar" />
</fileset>
</path>发布于 2019-04-25 19:26:00
您可以使用ant 1.10.5替换ant 1.9.4上的插件依赖项,如下所示:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
</dependency>
<executions>
...
</executions>
<configuration>
...
</configuration>
</dependencies>
</plugin>发布于 2019-04-25 19:30:07
根据http://svn.apache.org/viewvc/maven/plugins/tags/maven-antrun-plugin-1.8/pom.xml?view=markup的说法
事实上,他们将Ant 1.9.4用于1.8版本的插件。您是否尝试通过排除此依赖项来覆盖此依赖项:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<type>maven-plugin</type>
<exclusions>
<exclusion>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>然后显式地添加你想要的版本?
https://stackoverflow.com/questions/55711525
复制相似问题