从Maven运行Ant任务 [英] Run Ant task from Maven
问题描述
我正在使用Ant构建一个自定义的jar库,然后在Maven中将其用作依赖项.
I'm using Ant to build a custom jar library, which then I'm using in Maven as dependency.
<dependency>
<groupId>test-lib</groupId>
<artifactId>test-lib</artifactId>
<version>1.0.0system</scope>
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/test-lib-1.0.0.jar</systemPath>
</dependency>
所以,基本上我现在要做的是:
So, basically what I do now is:
1)运行ant来构建自定义库(test-lib-1.0.0.jar)
2)运行:mvn compile,使用自定义库来编译我的项目.
1) run ant to build custom library (test-lib-1.0.0.jar)
2) run: mvn compile, to compile my project using custom library among others.
我是否可以选择执行以下所有操作(打包自定义jar和编译项目)? Maven? 我找到了maven run插件,这是我的设置:
Is there an option for me to do all this (packaing custom jar & compiling project) from Maven? I've found maven run plugin, and here are my settings:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4
<executions>
<execution>
<phase>?????what to put here?????/phase>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml">
<target name="prepare-test-lib" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
但是,当运行:mvn compile
时,它会抱怨缺少工件:test-lib-1.0.0.jar
.
我在<phase/>
标记中使用了compile,generate-resouces ...,但是似乎没有任何作用.
But, when running: mvn compile
it complains about missing artifact: test-lib-1.0.0.jar
.
I've used compile, generate-resouces,... in <phase/>
tag, but nothing seems to work.
是否可以使用此插件以某种方式解决此问题?
Is it possible to solve this somehow using this plugin?
推荐答案
在使用Maven Antrun插件时,Maven尝试解析依赖项以构建
When using the Maven Antrun Plugin, Maven tries to resolve the dependencies to build ClassPaths for the AntRun invocation and you thus face a chicken and egg problem : you can't declare a dependency that will be created during AntRun execution that requires this dependency to run. This can't work.
我的建议是修饰您的test-lib
,将其包含在项目构建中并声明对其的常规依赖关系.换句话说,我的意思是从Ant迁移到Maven以构建您的test-lib
并设置一个多模块项目.
为了更直观地"说明事物,如下所示:
My recommendation would be to mavenize your test-lib
, to include it in your project build and to declare a regular dependency on it. In other words, what I mean is moving from Ant to Maven to build your test-lib
and setting up a multi-modules project.
To illustrate things more "visually", something like this:
my-project
|-- my-module
| |-- src
| | `-- main
| | `-- java
| `-- pom.xml
|-- test-lib
| |-- src
| | `-- main
| | `-- java
| `-- pom.xml
`-- pom.xml
其中my-project/pom.xml
是带有<packaging>pom</packaging>
的聚合pom,并在<modules>
元素下列出模块:
Where my-project/pom.xml
is an aggregating pom with a <packaging>pom</packaging>
and list the modules under a <modules>
element:
<modules>
<module>my-module</module>
<module>test-lib</module>
</modules>
其中my-module/pom.xml
声明对test-lib
工件的依赖性:
And where my-module/pom.xml
declares a dependency on the test-lib
artifact:
<dependency>
<groupId>your.group.id</groupId>
<artifactId>test-lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
在这里我只是提供一个非常高级的概述,您需要阅读一些文档以获取详细信息,我无法涵盖所有内容.从Sonatype的第一本书开始(下面的链接).
I'm just giving a very high-level overview here, you need to read the documentation a bit for the details, I can't cover everything. Start with the first book from Sonatype (link below).
但这是正确的方法(您不应该(ab)使用system
范围内的依赖项).
But that would be the right way to go (and you should just not (ab)use system
scoped dependencies).
这篇关于从Maven运行Ant任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!