Maven 作用域测试需要解决依赖关系
Maven scope test needs to resolve depdencies
我的 pom 依赖于 <scope>test</scope>
。据我了解 maven 的范围概念,仅在测试构建期间才需要依赖性。尽管如此,maven 会尝试在 mvn package
期间下载依赖项,这就是为什么我遇到以下构建失败的原因:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.278 s
[INFO] Finished at: 2016-04-19T22:11:59+02:00
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project my-module: Could not resolve dependencies for project com.mycompany.app:my-module:jar:1: Failure to find group-a:artifact-b:jar:tests:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]0
我使用以下 pom:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- 这是 maven 的预期行为吗?
- 在 package/install/deploy 构建期间是否有任何缓解措施来忽略依赖项?
感谢任何帮助
我无法解决问题,但我找到了一种缓解问题的舒适方法。在我的包裹中,我使用 -Dmaven.test.skip=true
参数。所以我定义了两个配置文件,一个有依赖关系,一个没有。跳过测试时,我会停用具有依赖性的配置文件。
尽管如此,我还是希望能有一个带有 scope
标签的解决方案
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>skip-tests</id>
<activation>
<property>
<name>maven.test.skip</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>
我的 pom 依赖于 <scope>test</scope>
。据我了解 maven 的范围概念,仅在测试构建期间才需要依赖性。尽管如此,maven 会尝试在 mvn package
期间下载依赖项,这就是为什么我遇到以下构建失败的原因:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.278 s
[INFO] Finished at: 2016-04-19T22:11:59+02:00
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project my-module: Could not resolve dependencies for project com.mycompany.app:my-module:jar:1: Failure to find group-a:artifact-b:jar:tests:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]0
我使用以下 pom:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- 这是 maven 的预期行为吗?
- 在 package/install/deploy 构建期间是否有任何缓解措施来忽略依赖项?
感谢任何帮助
我无法解决问题,但我找到了一种缓解问题的舒适方法。在我的包裹中,我使用 -Dmaven.test.skip=true
参数。所以我定义了两个配置文件,一个有依赖关系,一个没有。跳过测试时,我会停用具有依赖性的配置文件。
尽管如此,我还是希望能有一个带有 scope
标签的解决方案
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>skip-tests</id>
<activation>
<property>
<name>maven.test.skip</name>
<value>true</value>
</property>
</activation>
</profile>
</profiles>
</project>