【发布时间】:2020-05-06 00:36:26
【问题描述】:
在多模块 Maven 项目中,其中一个模块是阴影模块(例如,没有源,但在 package 阶段生成 jar)。其他模块将此模块作为依赖项引用(都在同一个父级下)。有没有办法让 Eclipse 将阴影模块识别为依赖项? Eclipse 最多只能覆盖compile。
目前它可以在命令行上运行(因为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 构建中只运行编译阶段。
【问题讨论】:
-
我不知道,但是如果您提供一个简单的 POM 示例(生成 jar)以及您在 Eclipse 中遇到的错误,您的问题可能会引起更多关注。
-
添加细节到原件
-
Eclipse 中显示了哪些错误?
-
"导入 my.shaded.third.party 无法解析"
-
一种可能的解决方法是将
maven-shade-plugin绑定到generate-sources阶段(这实际上是有道理的:您是通过重新定位以某种方式生成源一个现有的包)。
标签: eclipse maven module dependencies m2e