问题
In a multi-module Maven project, one of the modules is a shaded module (e.g. no source, but generates a jar
during package
phase). Other modules reference this module as a dependency (all under same parent). Is there a way to have Eclipse recognize the shaded module as a dependency? Eclipse only covers up to compile
.
Currently it works on the command line (since package
is run), but in Eclipse it shows errors.
I have not been able to find a solution to this.
Details:
- Parent project
- Module A
- Module B
Module A is a shaded module meaning it has something like:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.third.party</pattern>
<shadedPattern>my.shaded.third.party</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Module B has Module A as a dependency (under dependencies-dependency). Module B tries to use classes from Module A by importing the relocated paths ...e.g:
import my.shaded.third.party.Foo;
This doesn't work because it can't find Foo. This makes sense since only compile phase is run in Eclipse build.
回答1:
Rightclick on dependent project > Maven > Disable Workspace Resolution
This will tell Eclipse to use Maven's compilation instead, meaning you will be able to use my.shaded.*
imports.
However, this does have the consequence that your projects will not be updated until you build them using maven. It is a solution to get Eclipse to recognise shaded dependencies, nevertheless.
来源:https://stackoverflow.com/questions/33155779/maven-eclipse-multi-module-shaded-dependency