简体   繁体   English

如何使用Maven插件的修补版本?

[英]How can I use a patched version of a Maven plugin?

I would like to use a modified version of a Maven plugin in my build (for experimental purposes). 我想在我的构建中使用Maven插件的修改版本(用于实验目的)。 Therefore, I downloaded the source code of the plugin and adjusted it. 因此,我下载了插件的源代码并进行了调整。

What is the best way to integrate the modified plugin? 集成修改后的插件的最佳方法是什么? Can I intercept the loading of the Maven plugin and redirect it to a local jar? 我可以拦截Maven插件的加载并将其重定向到本地jar吗? Can I alternatively add the (few) adjusted classes in a way such that the they are loaded (by the classloader) before the plugin? 我可以选择添加(少数)调整后的类,以便在插件之前加载它们(由类加载器加载)吗? How? 怎么样?

Maven finds plugins the same way that it finds dependencies. Maven以找到依赖项的方式查找插件。 So here is what I would try: 所以这是我会尝试的:

  1. Change the plugin's group id / artifact id / version number in its POM file and rebuild it. 在其POM文件中更改插件的组ID /工件ID /版本号并重建它。

  2. Install the plugin into your .m2repository; 将插件安装到.m2repository中; eg run mvn install . 例如,运行mvn install

Alternatively after building the plugin JAR (however you do it), install it by running mvn install:install-file as described in Apache > Maven > Plugins > Apache Maven Install Plugin > Usage . 或者在构建插件JAR之后(不管你这样做),通过运行mvn install:install-file来安装它,如Apache> Maven> Plugins> Apache Maven Install Plugin> Usage中所述 This allows you to specify the group id / artifact id / version directly. 这允许您直接指定组ID /工件ID /版本。

It is advisable to choose a group/artifact/version that are unlikely to collide with an official version of the plugin. 建议选择不太可能与插件的正式版本冲突的组/工件/版本。 But that's for your sanity only. 但那只是为了你的理智。

The downside of doing this is that (now) you are likely to have to publish or distribute your plugin along with your project source code. 这样做的缺点是(现在)您可能必须发布或分发您的插件以及项目源代码。 And maintain it to track changes in the original plugin. 并保持它以跟踪原始插件中的更改。 (Or don't let your experimental plugin escape.) (或者不要让你的实验性插件逃脱。)

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

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