在Maven依赖项中同时指定jar和test-jar类型 [英] Specify both jar and test-jar types in Maven dependencies
问题描述
我有一个名为"commons"的项目,其中包含用于运行时和测试的通用包含项.
I have a project called "commons" that contains common includes for both runtime and test.
在主项目中,我添加了对公地的依赖:
In the main project I added a dependency for commons:
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
但是不包括测试通用文件.所以我加了:
However the test common files are not included. So I added :
<dependency>
<groupId>com.alexb</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
</dependency>
但是,当类型为test-jar时,不包括运行时.
However when type is test-jar, the runtime is not included.
不幸的是,看来我不能同时包括两者:
Unfortunatelly, it seems I cannot include both:
<type>jar,test-jar</type>
该怎么做才能同时包含两者?
What can I do to include both?
推荐答案
正如评论中提到的@khmarbaise,您应该分离测试罐零件项目.
As @khmarbaise mentioned in the comments you should separate your test-jar part project.
我假设您在commons
pom.xml中具有类似这样的内容,它会生成通用的测试jar.
I presume you have in the commons
pom.xml something like this which generates common test-jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
这种方法的问题在于,您不会自动获得可传递测试范围的依赖项.
The problem with this approach is that you don't get the transitive test-scoped dependencies automatically.
检查此链接以获取更多详细信息:
Check this link for more details:
https://maven.apache .org/plugins/maven-jar-plugin/examples/create-test-jar.html
这篇关于在Maven依赖项中同时指定jar和test-jar类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!