我们有一个包含大约十几个子项目的父项目.大多数子项目都有测试,因此它们依赖于JUnit.我认为将它作为托管依赖项提取到父pom是有意义的:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
在我的一个子项目中 - 仍在努力清理这个 - 我在构建期间需要JUnit.那个pom我现在有:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这很好用.事情崩溃的部分是,该项目还需要构建为具有依赖关系的jar,使用:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>TestIntegration</finalName>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
jar-with-dependencies缺少JUnit.请注意,如果我将JUnit作为托管依赖项删除,并将其指定为该项目中的普通依赖项,那么一切都很好.
我如何将jar作为测试范围内的托管依赖项加入jar-with-dependencies?
托管依赖项用于锁定父pom上的版本.这并不意味着junit会自动成为子项目的依赖项.
您需要将其指定为子项或父pom中的依赖项,以便将其包含在超级jar中
更新:我误解了这个问题,并认为OP只是要求使用依赖mgmt中声明的依赖项.
我如何将jar作为测试范围内的托管依赖项加入jar-with-dependencies?
依赖关系管理优先于依赖关系部分中声明的依赖关系 - 因此使用范围编译重新定义依赖关系中的依赖关系将不起作用.要解决此问题,请重新定义子pom的依赖关系管理部分中的依赖关系.
所以你的父母pom有:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
将此添加到您的孩子pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1935 次 |
| 最近记录: |