具有修补依赖项的Maven项目的布局 [英] A layout for maven project with a patched dependency

查看:81
本文介绍了具有修补依赖项的Maven项目的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设,我有一个依赖于某些库的开源项目,必须对其进行修补才能修复某些问题.我怎么做?我的想法是:

Suppose, I have an opensource project that depends on some library, that must be patched in order to fix some issues. How do I do that? My ideas are:

  1. 已将库源设置为模块,并将其保存在我的vcs中.优点:简单.缺点:我的仓库中有一些第三方资源,可能会减慢构建过程,难以找到修补位置(尽管可以在README中修复)
  2. 有一个模块(如1),但仅保留修补的源文件,用classpath中的原始库jar对其进行编译,并以某种方式替换构建时库jar中的* .class文件.优点:建造速度更快,易于找到打补丁的地方.缺点:难以配置,jar黑客不是显而易见的(存储库和我的项目程序集中的库jar会有所不同)
  3. 将已修补的* .class文件保留在主/资源中,并像2)中那样替换在包装上.优点:几乎没有.缺点:vcs中的二进制文件,由于补丁程序编译不是自动化的,因此很难重新编译补丁程序类.

一个不错的解决方案是创建一个带有修补库源代码的独特项目,然后使用-patched限定符将其部署在本地/企业存储库中.但这不适用于开放源代码项目,该项目应易于任何签出其源代码的人进行构建.还是我应该说而且,在构建我的项目之前,请先检查这些内容并运行mvn install".

One nice solution is to create a distinct project with patched library sources, and deploy it on local/enterprise repository with -patched qualifier. But that would not fit for an opensourced project that is meant to be easily buildable by anyone who checks out its sources. Or should I just say "and also, before you build my project, please check out that stuff and run mvn install".

推荐答案

一个不错的解决方案是使用补丁库源代码创建一个不同的项目,并使用-patched限定符将其部署在本地/企业存储库中.但这不适用于开放源代码项目,该项目应易于任何签出其源代码的人进行构建.还是我应该说而且,在构建我的项目之前,请先检查这些内容并运行mvn install".

One nice solution is to create a distinct project with patched library sources, and deploy it on local/enterprise repository with -patched qualifier. But that would not fit for an opensourced project that is meant to be easily buildable by anyone who checks out its sources. Or should I just say "and also, before you build my project, please check out that stuff and run mvn install".

这是我将要为公司和开源项目做的事情(实际上是我要做的事情).获取源代码,将其置于不同项目的版本控制下,对其进行补丁,重建补丁库(并将此信息包含在版本中,例如XYZ补丁),将其部署到存储库(您可以使用SVN, Google代码 1 ),在POM中声明存储库,并更新依赖项以指向已修补的版本.

This is what I would do (and actually what I do) for both a corporate and an opensource project. Get the sources, put them under version control in a distinct project, patch them, rebuild the patched library (and include this information in the version, something like X.Y.Z-patched), deploy it to a repository (you could use SVN for this, a la Google Code1), declare the repository in your POM and update the dependency to point on your patched version.

使用这种方法,您可以对用户说:签出我的代码并运行mvn install,他们将得到补丁版本,而无需任何其他操作.这是恕我直言,最干净的方法(不易出错,不导致类路径混乱,不增加构建时间,等等).

With this approach, you can say to your users: check out my code and run mvn install and they will just get the patched version without any extra action. This is IMHO the cleanest way (not error prone, no class path order mess, no increase of the build time, etc).

1 很多人正在将代码部署到其托管的Subversion存储库中(这篇文章).

1 Lots of people are deploying their code to their hosted subversion repository (how-to in this post).

这篇关于具有修补依赖项的Maven项目的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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