Maven Eclipse 多模块阴影依赖

2024-01-06

在多模块 Maven 项目中,其中一个模块是阴影模块(例如,没有源,但生成一个jar during package阶段)。其他模块将此模块作为依赖项引用(全部位于同一父模块下)。有没有办法让 Eclipse 将着色模块识别为依赖项? Eclipse 仅覆盖compile.

目前它可以在命令行上运行(因为package已运行),但在 Eclipse 中显示错误。

我一直无法找到解决方案。

Details:

- 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 作为依赖项(在依赖项-依赖项下)。模块 B 尝试通过导入重定位的路径来使用模块 A 中的类...例如:

import my.shaded.third.party.Foo;

这不起作用,因为它找不到 Foo。这是有道理的,因为 Eclipse 构建中只运行编译阶段。


右键单击依赖项目 > Maven >禁用工作区分辨率

这将告诉 Eclipse 使用 Maven 的编译,这意味着您将能够使用my.shaded.*进口。

但是,这确实会导致您的项目在使用 Maven 构建之前不会更新。它is不过,这是一个让 Eclipse 识别阴影依赖项的解决方案。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Maven Eclipse 多模块阴影依赖 的相关文章

随机推荐