在多模块 Maven 项目中,其中一个模块是一个阴影模块(例如,没有源代码,但在 package
阶段生成一个 jar
)。其他模块将此模块引用为依赖项(都在同一父项下)。有没有办法让 Eclipse 将阴影模块识别为依赖项? Eclipse 只涵盖编译
。
目前它在命令行上工作(因为 package
运行),但在 Eclipse 中它显示错误。
我还没有找到解决办法。
详细信息:
- Parent project
- Module A
- Module B
模块 A 是一个带阴影的模块,表示它具有如下内容:
<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>
模块 B 将模块 A 作为依赖项(在 dependencies-dependency 下)。模块 B 尝试通过导入重定位路径来使用模块 A 中的类...例如:
import my.shaded.third.party.Foo;
这不起作用,因为它找不到 Foo。这是有道理的,因为在 Eclipse 构建中只运行编译阶段。
最佳答案
右键单击依赖项目 > Maven > 禁用工作区解析
这将告诉 Eclipse 使用 Maven 的编译,这意味着您将能够使用 my.shaded.*
导入。
但是,这确实会导致您的项目在您使用 maven 构建它们之前不会更新。不过,它是一种让 Eclipse 识别阴影依赖项的解决方案。
关于eclipse - Maven Eclipse 多模块阴影依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33155779/