我有一个多模块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模块进行着色。将shade
附加到此模块中的阶段test
。不要忘记依赖新模块。
mvn test
的代码失败,因为这不会创建任何JAR,因此不会调用Shade插件。
您可能想要将Shade运行的阶段更改为现有模块中的generate-test-resources
或test
,但如果在Maven lifecycle的后续阶段发生某些事情,则可能会导致其他问题。这就是为什么我建议创建一个没有其他副作用的新模块。