我正在使用Ant来构建一个自定义jar库,然后我在Maven中使用它作为依赖 .
<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>
所以,基本上我现在所做的是:
1)运行ant来构建自定义库(test-lib-1.0.0.jar)
2)运行:mvn编译,使用自定义库等编译我的项目 .
我可以选择从Maven做这一切(打包自定义jar和编译项目)吗?我找到了maven run plugin,这是我的设置:
<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,...但似乎没有任何效果 .
有可能使用这个插件以某种方式解决这个问题吗?
1 回答
当使用Maven Antrun插件时,Maven尝试解析依赖关系以构建用于AntRun调用的ClassPaths,因此您面临鸡和蛋问题:您可以't declare a dependency that will be created during AntRun execution that requires this dependency to run. This can'工作 .
我的建议是对你的
test-lib
进行编组,将其包含在项目构建中并声明对它的常规依赖 . 换句话说,我的意思是从Ant转移到Maven来构建你的test-lib
并设置a multi-modules project . 为了说明更多的事情"visually",这样的事情:其中
my-project/pom.xml
是一个带有<packaging>pom</packaging>
的聚合pom,并列出<modules>
元素下的模块:并且
my-module/pom.xml
声明了对test-lib
工件的依赖:我只是在这里给出一个非常高级的概述,你需要阅读文档一些细节,我无法涵盖所有内容 . 从Sonatype的第一本书开始(链接如下) .
但这将是正确的方法(你应该不(ab)使用
system
作用域依赖) .参考文献