maven-3 - Maven 多模块在将一个模块用于另一个模块之前对其进行遮蔽
问题描述
我有一个多模块 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 中引入这样的目标依赖项?
将阴影插件绑定到包以外的其他阶段会产生以下错误消息:
[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
或现有模块中的阶段,但如果在Maven 生命周期test
的后期阶段发生某些事情,这可能会导致其他问题。这就是为什么我建议创建一个没有其他副作用的新模块。
推荐阅读
- spring-boot - 如何配置 bootBuildImage 命令创建的镜像?
- python - django:在使用这种多对多关系之前,需要为字段“id”设置一个值
- ruby-on-rails - 按月排序日期而不计算年份 - Ruby on rails
- javascript - 尝试显示来自geojson的点时出现未捕获的错误:无效的LatLng对象:(NaN,NaN)
- unit-testing - 将 Jest 与 Firebase HTTP 云函数一起使用
- python - 在 Pandas 中为 API 发出批量请求
- ios - 自定义 UIView 上的 IntrinsicContentSize 拉伸内容
- python - 使用 --safe_resume --cb_explore 在 python 中保存和加载 Vowpal Wabbit 模型
- tensorflow - RuntimeError: 启用急切执行时 tf.device 不支持函数
- sqitch - 基线现有数据库