Maven多模块遮挡一个模块,然后在另一个模块中使用它

问题描述 投票:0回答:1

我有一个多模块Maven构建,其中一个模块对库进行着色,另一个模块使用共享库。

如果我运行mvn test,这会导致package com.example.shaded.javax.el7 does not exist

如果我运行mvn package test,编译和测试通过。

所以我想要的是阴影模块不仅要编译,而是在编译依赖模块之前运行maven-shade-plugin:3.2.1:shade进行着色(打包)。

是否有可能在pom.xml中的maven中引入这样的目标依赖?

将shade插件绑定到除package之外的其他阶段会产生以下错误消息:

[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.

maven-3 maven-shade-plugin multi-project
1个回答
1
投票

更新似乎没有一个干净的方法来做到这一点。

在两个之间插入一个新的Maven模块进行着色。将shade附加到此模块中的阶段test。不要忘记依赖新模块。

mvn test的代码失败,因为这不会创建任何JAR,因此不会调用Shade插件。

您可能想要将Shade运行的阶段更改为现有模块中的generate-test-resourcestest,但如果在Maven lifecycle的后续阶段发生某些事情,则可能会导致其他问题。这就是为什么我建议创建一个没有其他副作用的新模块。

© www.soinside.com 2019 - 2024. All rights reserved.