简体   繁体   English

当第三方Java库作为单个jar的集合提供时,将它集成到Maven项目中的最佳方法是什么?

[英]When a 3rd party Java library is supplied as a collection of individual jars, what is the best way to integrate it in a Maven project?

One of the 3rd party libraries used in my company is supplied to us as a zip file with tens of jars in it. 我公司使用的第三方库之一作为zip文件提供给我们,其中包含数十个罐子。 The library releases a new version every two weeks, so I am looking for a solution that does not require a lot of manual effort each time a new release is out. 该库每两周发布一个新版本,因此我正在寻找一种解决方案,每次新版本发布时都不需要大量的手动工作。 I have recently started using Maven for dependency management and I have found it very difficult to deal with this particular 3rd party library. 我最近开始使用Maven进行依赖管理,我发现很难处理这个特定的第三方库。 Should I... 我是不是该...

  1. add each individual jar to a company-internal repository (eg with Nexus) and then declare each one of them as a dependency to any new projects using this library? 将每个jar添加到公司内部存储库(例如使用Nexus),然后将每个jar声明为使用此库的任何新项目的依赖项? This is a laborious process and I can't imagine doing this for every new release. 这是一个费力的过程,我无法想象每个新版本都会这样做。

  2. create a jar of jars to add to our repository? 创建一罐罐子添加到我们的存储库? If so, how do I create it? 如果是这样,我该如何创建它? The Maven shade plugin would require that I mavenise the library first, right? Maven的阴影插件需要我首先对图书馆进行mavenise,对吧?

  3. any better suggestions? 更好的建议?

Your first option is the best practice. 您的第一个选择是最佳做法。 I'm not sure why it should be laborious. 我不确定为什么它应该是费力的。

  1. create a simple script to upload the various jars to nexus 创建一个简单的脚本,将各种罐子上传到nexus
  2. use a property in your pom to specify the third-party version so all deps can be changed with a simple property change in the pom 使用pom中的属性来指定第三方版本,以便可以通过pom中的简单属性更改来更改所有deps

Should be all of 5 minutes to add a new release to your build pipeline. 应该在5分钟内将新版本添加到构建管道中。

Alternative: convince the third-party to setup a maven repository for their customers to use! 替代方案:说服第三方为其客户设置maven存储库!

Its possible, but complicated (but only a 1 time effort) and probably a misuse of what maven's meant for: 它可能,但很复杂(但只有一次努力),可能是滥用maven的意思:

  1. Upload zip file to your local maven repo with a specific groupid:artifactId 将zip文件上传到具有特定groupid:artifactId的本地maven仓库
  2. Create a sub-module that has dependency on this zip file. 创建一个依赖于此zip文件的子模块。 Tis sub module should be used only for creating the uber jar Tis子模块应仅用于创建超级jar
  3. Use maven-dependency-plugin unpack goal to unpack the zip file into a directory 使用maven-dependency-plugin解压缩目标将zip文件解压缩到目录中
  4. Use maven antrun unzip to unzip the jars to a dir 使用maven antrun解压缩将jar解压缩到dir
  5. Use maven antrun zip to jar the files into a uber jar 使用maven antrun zip将文件装入超级罐中
  6. Use maven-intall-plugin to install uber jar to your local repo and use as a dependency. 使用maven-intall-plugin将uber jar安装到本地repo并用作依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM