我们将Maven与Ant的build.xml文件结合使用以用于buid。
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>
Run Code Online (Sandbox Code Playgroud)
maven-antrun-plugin内部使用Ant 1.9.4。有没有一种方法可以通过调用该内部ant jar来替换对$ {ant.exec}的依赖关系?
现在,我们将ant.exec传递给mvn命令。使用ant任务无效,因为我们还需要将-lib传递给ant。(lib文件夹包含所有下载的依赖项)。
使用此ant.exec方法的优点是我们可以使用ant 1.10.5。但是,我可以在依赖项中指定ant 1.10.5并将该jar下载到lib文件夹中。但是,除了启动ant.bat文件之外,我还需要一种使用1.10.5 jar启动ant的方法。
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>
Run Code Online (Sandbox Code Playgroud)
xlatedb.ant.xml
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
<echo>${target.dir}</echo>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
输出:
--- exec-maven-plugin:1.6.0:java (默认) @ stack-55711525-maven-antexec ---
构建文件:/xyz/project/xlatedb.ant.xml
打印版本:
[echo] Apache Ant( TM)版本1.10.5编译于2018年7月10日
[echo] theTargetDirectory
BUILD SUCCESSFUL
总时间:0秒
注意:如果您想让 Maven 类路径在 期间可供 ant 使用jar,我想您可以copy-dependencies在生命周期中尽早运行插件,然后提供依赖项输出目录作为 ant 的类路径。
例如
<path id="class.path">
<fileset dir="target">
<include name="copied-dependencies-dir/*.jar" />
</fileset>
</path>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
345 次 |
| 最近记录: |