[英]Maven test dependencies of dependency
I have a parent project which has dependencies with scope test 我有一个父项目与范围测试有依赖性
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
<scope>test</scope>
</dependency>
Now I "mvn install"ed the parent project, when I include this parent project as dependency in my child project 现在,当我将此父项目作为依赖项包含在我的子项目中时,我“ MVN安装”了父项目
<dependency>
<groupId>group</groupId>
<artifactId>parentproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
selenium-firefox-driver
is not available. selenium-firefox-driver
不可用。 The compile scoped dependencies are available. 编译范围的依赖项可用。
How can I make it available? 我如何使它可用? I won't change the scope neither in the parent project nor in the child project.
在父项目或子项目中,我都不会更改范围。 Because I need some classes of the parent in at runtime
因为我在运行时需要一些父类
Instead of including the parent project as dependency in your child pom, you should make the parent project as the parent
of your child pom. 不应将父项目作为子pom的依赖项包含在内,而应将父项目作为子pom的
parent
项。
<parent>
<groupId>group</groupId>
<artifactId>parentproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
You cannot call it a parent project
otherwise. 否则,您不能将其称为
parent project
。
As outlined by Charlee Chitsuk in his answer, your scope ( compile in the child project) will omit the test dependencies of the included project. 正如Charlee Chitsuk在他的回答中所概述的那样,您的范围(在子项目中编译 )将忽略所包含项目的测试依赖项。
A clean solution would be to separate the concerns of the parent project into two separate projects: 一个干净的解决方案是将父项目的关注点分为两个单独的项目:
selenium-firefox-driver
) with a compile scope. selenium-firefox-driver
)。 Additionally, this project contains all of your generic test resources, eg JUnit base classes, in src/main/java
. src/main/java
包含所有通用测试资源,例如JUnit基类。 parent-test
here with test
scope. parent-test
包含在test
范围内。 In your child project, you can now include parent-test
with scope test as well, giving you access to its resources with the right scope. 现在,在子项目中,您还可以将
parent-test
包括在范围测试中,从而可以使用正确的范围访问其资源。
This setup will provide a clear project structure with clean scoping, avoiding issues like you have mentioned. 此设置将提供清晰的项目结构和清晰的范围,避免出现您提到的问题。 Yes, it's a bit more complex due to the additional project, but it's a lot cleaner as well.
是的,由于增加了项目,所以它有点复杂,但是也更干净。
The Dependency Scope told that the compile
is the default scope, used if none is specified. Dependency Scope告知
compile
是默认范围,如果未指定,则使用默认范围。 It affects transitive dependencies in different ways. 它以不同的方式影响传递依赖。 By overview if the dependency is
compile
scope, the transitive test
scope will be omitted. 通过概述,如果依赖项是
compile
范围,则将忽略传递test
范围。 Please see further information at Maven: The Complete Reference: Project Dependencies . 请在Maven:完整参考:项目依赖项中查看更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.