Question

I have Java project build with maven that has some dependencies. One of such dependencies is another project (I have Eclipse workspace in mind) and it is only in test scope.

    <dependency>
        <groupId>my.group.id</groupId>
        <artifactId>artifactid</artifactId>
        <version>1.0</version>
        <scope>test</scope>
    </dependency>

I build my projects using following command inside project root dir

mvn clean package -Dmaven.test.skip=true

what I expected to happen it that maven would build project leaving test dependencies behind. However unresolved dependency exception is thrown (unresolved to my test scoped dependency). As I ran build command with -X option, I spoted following report in my project build plan:

[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [compile, runtime, test]
[DEBUG] Repositories (dependencies): [central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] Repositories (plugins)     : [central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] -----------------------------------------------------------------------

So despite skipping tests and even compiling them (mvn clean compile runs fine) maven tries to resolve test dependencies.

How to exclude test dependencies from build plan dependency resolving step when skipping test executions?

Was it helpful?

Solution

In short: you can't. At least not easily. maven.test.skip does not prevent the surefire:test mojo from running, it only configures the plugin to do nothing. (same for compile:testcompile).

Both mojos need dependency resolving of scope test (part of the mojo definition).

So, the only options of preventing those dependencies from being resolved would be either:

  • Use a profile and rebind compiler:testCompile as well as surefire:test to non existing phases
  • put all your test dependencies in a separate profile

However, both options are rather dirty.

So your best bet would be to install your dependent artifacts first (using mvn install) and simply accept the way maven resolves dependencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top