Reputation: 1079
I have Maven dependencies with scope test.
I add flag Dmaven.test.skip=true
but Maven still brings test dependencies.
Is there a way not to bring test dependencies if I want to build only the production part?
Upvotes: 1
Views: 2919
Reputation: 51
If you add some dependencies for test scope, maven will first check if the dependency is available or not then it checks the scope.
You can create a maven profile, add test dependencies under the profile and trigger the profile when -Dmaven.test.skip
or -Dmaven.test.skip=true
option is not present. In this way you can keep your build command unchanged.
You can check this simple project manage-test-dependencies-in-maven-the-proper-way to understand it better.
Upvotes: 1
Reputation: 7710
This is how maven works - it First tries to check that ako dependencies are available, no matter their scope. Only then it continues to test phase to find out that tests should not be executed.
A possible workaround is to define your test dependencies in a separate test maven profile, which is not applied when you do not want to run tests. Profiles are resolved before any dependence are downloaded, therefore if test dependencies are not added by the profile to the effective pom, they are not downloaded at all.
Upvotes: 3
Reputation: 8160
the flag -Dmaven.test.skip
will only skip compilation and execution of your tests within the project you run.
Its often better to use -DskipTests
as this will compile the test classes but not run them. See surefire documentation.
This has nothing to do with dependencies. Those are loaded into the classpath depending on their scope and what plugins require. The surefire plugin requires resolution of scope test as it runs the unit tests.
If there are dependencies of scope test which you do not want to use you need to remove them or exclude them if they come in via transitive dependencies (dependencies of dependencies). You can execute a mvn dependency:tree
to figure out why jar are in the project.
Upvotes: 2