maven - How to build uberjars with dependencies

天大地大妈咪最大 提交于 2019-12-11 03:50:09

问题


I have a maven module generating a jar file. I have been asked to develop a couple of other uberjar files as a byproduct of build process. I have also been told these 2 jar files are applet jar files that will be need include some classes from the dependencies of the maven module.

I looked around and narrowed down to these 3 options -

  1. Maven Assembly plugin - This can build custom jars from the classes generated by the maven module. Third party dependencies cant be included.
  2. Use ant through Maven - Use maven-dependency-plugin to unpack dependencies and then pack the applet jars through ant scripts.
  3. Use Maven shade plugin - Although this plugin is not directly suited for my requirement, I can get it working.

While I can get things working with (b) and (c), I am unable to decide which one to use. One key thing I have noticed is using the dependency plugin is time consuming.

I wanted to know if there are other ways people achieve the same requirement.


回答1:


You can include dependencies using the assembly plugin with the dependencySet elements, see:

  • http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet

Specifically here's an example taken from Andrew E Bruno's blog:

<dependencySets>
  <dependencySet>
    <outputDirectory></outputDirectory>
    <outputFileNameMapping></outputFileNameMapping>
    <unpack>true</unpack>
    <scope>runtime</scope>
    <includes>
      <include>commons-lang:commons-lang</include>
      <include>commons-cli:commons-cli</include>
    </includes>
  </dependencySet>
</dependencySets>



回答2:


I finally used the assembly plugin using the same approach you described above. I moved away from shade plugin since I generate several assemblies with resources from outside of maven also and shade plugin does not have great support for such tasks.



来源:https://stackoverflow.com/questions/10096723/maven-how-to-build-uberjars-with-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!