我test-jar
在多模块项目中使用依赖项时遇到问题。例如,当我声明cleartk-syntax
模块依赖于cleartk-token
模块时test-jar
(完整代码在这里):
<modelVersion>4.0.0</modelVersion>
<groupId>org.cleartk</groupId>
<artifactId>cleartk-syntax</artifactId>
<version>0.5.0-SNAPSHOT</version>
<name>cleartk-syntax</name>
...
<dependencies>
...
<dependency>
<groupId>org.cleartk</groupId>
<artifactId>cleartk-token</artifactId>
<version>0.7.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
如果我mvn compile
使用 maven 2 运行,我会收到以下错误:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) org.cleartk:cleartk-token:test-jar:tests:0.7.0-SNAPSHOT
如果我使用 maven 3,我会收到错误消息:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.654s
[INFO] Finished at: Mon Jan 24 21:19:17 CET 2011
[INFO] Final Memory: 16M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project cleartk-syntax: Could not resolve
dependencies for project org.cleartk:cleartk-syntax:jar:0.5.0-SNAPSHOT: Could
not find artifact org.cleartk:cleartk-token:jar:tests:0.7.0-SNAPSHOT
在后一种情况下,我特别困惑,因为我认为它应该寻找 type 的 artifact 而test-jar
不是 type jar
。
使用 maven 2 或 maven 3,我可以通过运行mvn compile package -DskipTests
. 使用 maven 3,我还可以通过运行mvn compile test-compile
.
但是为什么 maven 2 或 maven 3 在该阶段寻找test-jar
依赖项compile
?难道不应该等到test-compile
寻找这种依赖的阶段吗?
更新:答案是在我的编译阶段使用的 maven-exec-plugin需要对 scope:test 中的工件进行依赖解析。我创建了一个功能请求来删除 scope:test 依赖项。