简体   繁体   English

Maven Eclipse 多模块阴影依赖

[英]Maven Eclipse multi-module shaded dependency

In a multi-module Maven project, one of the modules is a shaded module (eg no source, but generates a jar during package phase).在多模块 Maven 项目中,其中一个模块是阴影模块(例如,没有源代码,但在package阶段生成一个jar )。 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 将阴影模块识别为依赖项? Eclipse only covers up to compile . Eclipse 只覆盖compile .

Currently it works on the command line (since package is run), but in Eclipse it shows errors.目前它在命令行上工作(因为package已运行),但在 Eclipse 中它显示错误。

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:模块 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>

Module B has Module A as a dependency (under dependencies-dependency).模块 B 将模块 A 作为依赖项(在依赖项-依赖项下)。 Module B tries to use classes from Module A by importing the relocated paths ...eg:模块 B 尝试通过导入重定位路径来使用模块 A 中的类......例如:

import my.shaded.third.party.Foo;

This doesn't work because it can't find Foo.这不起作用,因为它找不到 Foo。 This makes sense since only compile phase is run in Eclipse build.这是有道理的,因为在 Eclipse 构建中只运行编译阶段。

Rightclick on dependent project > Maven > Disable Workspace Resolution右键单击依赖项目 > Maven >禁用工作区解析

This will tell Eclipse to use Maven's compilation instead, meaning you will be able to use my.shaded.* imports.这将告诉 Eclipse 改用 Maven 的编译,这意味着您将能够使用my.shaded.*导入。

However, this does have the consequence that your projects will not be updated until you build them using maven.但是,这确实会导致您的项目在您使用 maven 构建它们之前不会更新。 It is a solution to get Eclipse to recognise shaded dependencies, nevertheless.一个解决方案,使Eclipse能够识别阴影依存关系,不过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM