maven - How to exclude {test} scoped dependencies from build? -
i have java project build maven has dependencies. 1 of such dependencies project (i have eclipse workspace in mind) , in test
scope.
<dependency> <groupid>my.group.id</groupid> <artifactid>artifactid</artifactid> <version>1.0</version> <scope>test</scope> </dependency>
i build projects using following command inside project root dir
mvn clean package -dmaven.test.skip=true
what expected happen maven build project leaving test dependencies behind. unresolved dependency exception thrown (unresolved test
scoped dependency). ran build command -x
option, spoted following report in 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 , compiling them (mvn clean compile
runs fine) maven tries resolve test dependencies.
how exclude test dependencies build plan dependency resolving step when skipping test executions?
in short: can't. @ least not easily. maven.test.skip
not prevent surefire:test mojo running, configures plugin nothing. (same compile:testcompile).
both mojos need dependency resolving of scope test (part of mojo definition).
so, options of preventing dependencies being resolved either:
- use profile , rebind compiler:testcompile surefire:test non existing phases
- put test dependencies in separate profile
however, both options rather dirty.
so best bet install dependent artifacts first (using mvn install
) , accept way maven resolves dependencies.
Comments
Post a Comment