eclipse - Maven Eclipse 多模块阴影依赖

标签 eclipse maven module dependencies m2e

在多模块 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/

相关文章:

java - 获取带有 fragment 的布局的 inflate ViewGroup

java - Eclipse 找不到 Java 运行时

java - kafka 和 kafka-clients 有什么区别?

import - 如何使用 Cargo/Rust 在模块中包含同一目录中的文件?

Javascript、多文件模块和 Require.Js

java - eclipse GWT "There are no CSS files referenced"

c++ - Eclipse 调试 : "Error in final sequence - Failed to execute MI command"

java - Spring mvc @PathVariable 给出 'The request sent by the client was syntactically incorrect.'

java - Maven - 如何通过命令行为java项目创建pom.xml

linux -/proc/modules 中模块实例的含义