I have a multi-module project a
. Sub-module x
includes an a simple integration test which requires also a dependency on sub-module y
.
I would like to be able to separate the compilation and package phase from running the tests. When I run the following command, the integration test run successfully
mvn clean verify
When I run the following command, it fails
mvn clean package && mvn failsafe:integration-test failsafe:verify
[ERROR] Failed to execute goal on project x: Could not resolve dependencies for project a:x:jar:1.0-SNAPSHOT: Could not find artifact a:y:jar:1.0-SNAPSHOT -> [Help 1]
The underlying reason is that I would like to run the unit-tests and various integration tests each in separate jenkins tasks after the compilation completes (without running compile and package phase again). Reproducible code is here https://github.com/itaifrenkel/failsafe-test. Using Maven version 3.2.1.
Clarification: I cannot mvn install on jenkins machine since I have concurrent builds of different git versions (that have the same maven version).
When you execute mvn clean verify
, the build succeeds: Maven resolves the y
dependency because it is in the same project reactor and y
was packaged successfully into a jar
inside this reactor. If you take a look at the log, you will notice that this command triggered the maven-jar-plugin
, which is expected since this plugin is bound to the package
phase and verify
phase comes after it in the build lifecycle.
The command mvn clean package && mvn failsafe:integration-test failsafe:verify
actually executes 2 commands. First, mvn clean package
will succeed and package the application (same reason as before: y
is in the reactor and is packaged into a jar
).
However, for the second build, mvn failsafe:integration-test failsafe:verify
, since y
was not packaged into a jar
inside the reactor, Maven can't resolve the dependency directly so it needs to look for it in the repository. Since this artifact was never installed in the repository (and is obviously not available in Maven Central), the dependency can't be resolved, hence the error message
As such, you have 2 possible solutions:
Install the y
dependency into the local repository with mvn install
:
mvn clean install && mvn failsafe:integration-test failsafe:verify
Running jar:jar
before the integration tests so that Maven can resolve the y
dependency. This does not rebuild the project: it makes the assumption that the project was already built before by simply asking maven-jar-plugin
to make a jar
out of the result of the previous build.
mvn clean package && mvn jar:jar failsafe:integration-test failsafe:verify