Reputation: 10695
I have a multi-module Maven build where one module shades a library, and another module uses the shared library.
If I run mvn test
, this results in package com.example.shaded.javax.el7 does not exist
.
If I run mvn package test
, the compilation and tests pass.
So what I would like is for the shaded module to not just compile but be shaded (packaged) running maven-shade-plugin:3.2.1:shade
before the dependent module is compiled.
Is it possible to introduce such a target dependency in maven in the pom.xml?
Binding the shade plugin to other phases than package yields this error message:
[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR] supported. Please add the goal to the default lifecycle via an
[ERROR] <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR] remove this binding from your POM such that the goal will be run in
[ERROR] the proper phase.
Upvotes: 2
Views: 517
Reputation: 328624
Update There doesn't seem to be a clean way to do this.
Insert a new Maven module between the two which does the shading. Attach shade
to the phase test
in this module. Don't forget to depend on the new module.
The code fails for mvn test
because this doesn't create any JARs and therefore doesn't invoke the Shade plugin.
You may be tempted to change the phase in which Shade is run to generate-test-resources
or test
in the existing module but that could cause other problems if something happens in later phases of the Maven lifecycle. That's why I suggest to create a new module where you have no other side effects.
Upvotes: 1