Maven Eclipse多模块阴影依赖 [英] Maven Eclipse multi-module shaded dependency

查看:228
本文介绍了Maven Eclipse多模块阴影依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多模块Maven项目中,模块之一是带阴影的模块(例如,无源,但在package阶段生成jar).其他模块将此模块作为依赖项引用(均在同一父项下).有没有办法让Eclipse将阴影模块识别为依赖项? Eclipse最多只能涵盖compile.

In a multi-module Maven project, one of the modules is a shaded module (e.g. no source, but generates a jar during package phase). 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 only covers up to compile.

当前它可以在命令行上运行(因为运行package),但是在Eclipse中它显示错误.

Currently it works on the command line (since package is run), but in Eclipse it shows errors.

我无法找到解决方案.

详细信息:

- Parent project
   - Module A
   - Module B

模块A是带阴影的模块,这意味着它具有以下内容:

Module A is a shaded module meaning it has something like:

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

Module B has Module A as a dependency (under dependencies-dependency). Module B tries to use classes from Module A by importing the relocated paths ...e.g:

import my.shaded.third.party.Foo;

这行不通,因为找不到Foo.这是有道理的,因为在Eclipse构建中仅运行编译阶段.

This doesn't work because it can't find Foo. This makes sense since only compile phase is run in Eclipse build.

推荐答案

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

Rightclick on dependent project > Maven > Disable Workspace Resolution

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

This will tell Eclipse to use Maven's compilation instead, meaning you will be able to use my.shaded.* imports.

但是,这样做的结果是,直到您使用maven生成项目后,您的项目才会被更新.不过,它 是一种使Eclipse能够识别阴影依赖项的解决方案.

However, this does have the consequence that your projects will not be updated until you build them using maven. It is a solution to get Eclipse to recognise shaded dependencies, nevertheless.

这篇关于Maven Eclipse多模块阴影依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆