在多模块项目中使用Maven阴影插件-NullPointerException [英] Using Maven shade plugin in a multi module project - NullPointerException

查看:385
本文介绍了在多模块项目中使用Maven阴影插件-NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,其中我需要创建一个包含所有模块及其依赖项的多模块Maven项目的uber jar.我尝试使用Maven Shade插件.但它似乎仅在模块级别使用时才有效.如果我在父pom中添加插件条目,则构建会中断(它将尝试隐藏父pom)

I have a scenario where-in I need to create an uber jar of a multi module maven project including all modules and their dependencies. I tried using maven shade plugin. but it seems to work only when I use it at the module level. If I add the plugin entry in parent pom then the build breaks (it tries to shade the parent pom)

 [INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing null with C:\Projects\foo.bar\target\foobar-0.0.1-SNAPSHOT-shaded.pom
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error creating shaded jar: null: NullPointerException -> [Help 1]

这似乎很有意义,因为父maven项目的<packaging>是pom. 但是应该有某种方法可以为多模块项目创建一个超级罐子.

It does seem to make sense since the <packaging> for the parent maven project is pom. But there should be some way to create an uber jar for a multi module project... Any ideas people???

推荐答案

您不应该使用父项目的POM文件尝试着色.您应该为此使用单独的聚合器项目.父Maven项目用于继承,而聚合器项目用于在一组子项目上执行聚合功能.就像将其JAR一起着色到一个超级jar中一样.该项目只是您项目的根目录(与所有子模块的文件夹处于同一级别)上的pom文件,该文件引用了子项目并具有shade插件配置.确保为此pom指定的包装为JAR.

You should not be using your parent project's POM file to attempt shading; you should be using a separate aggregator project for this. Parent maven projects are used for inheritance while aggregator projects are used to perform aggregate functions over a group of sub-projects; like shading their JARs together into a uber jar. This project would simply be a pom file at the root directory of your project (the same level as all the sub-modules' folders) which references the sub-projects and has the shade plugin configuration. Make sure the packaing specified for this pom is JAR.

这是文档,用于解释POM关系以及聚合与继承之间的区别.

Here is the documentation explaining POM relationships and difference between Aggregation and Inheritance.

这篇关于在多模块项目中使用Maven阴影插件-NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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