2

I have a dependency in my pom with <scope>test</scope>. As I understood the scope concept of maven the dependency should only be required during test builds. Nevertheless maven trys to download the dependency during a mvn package which is why I get following build failure:

[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 

I use following 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>
  1. Is this intended behavior of maven?
  2. Are there any mitigations to ignore the dependency during package/install/deploy builds?

Any help is appreciated

1 Answers1

0

I couldn't solve the issue, but I found a comfortable way to mitigate the problem. Durring my package I use -Dmaven.test.skip=true parameter. So I defined two profiles one with the dependency and one without. When tests are skipped I deactivate the profile with the dependency.

Nevertheless I would appreciate a solution with the scope tag

<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>