简体   繁体   English

如何在maven pom.xml中使用自定义插件?

[英]How to use custom plugin in maven pom.xml?

I created one custom plugin in maven. 我在maven中创建了一个自定义插件。 So when run this project then automatically created related one JAR file. 因此,在运行该项目时,会自动创建一个相关的JAR文件。 So now i created one more project in maven in this project how to use that jar file in the pom.xml file. 因此,现在我在该项目的maven中创建了另一个项目,该项目如何使用pom.xml文件中的jar文件。 Is there any possible to use already existing jars in pom.xml file. 有没有可能使用pom.xml文件中已经存在的jar。

I'm a little unsure of what you're getting at- my understanding is that you wrote a plugin that you now want to use in a separate project. 我不确定您能得到什么-我的理解是您编写了一个插件,现在想在单独的项目中使用。 In order to do this, you would add the custom plugin to your section in the new project. 为此,您可以将自定义插件添加到新项目的部分中。 It will resolve this the same way it does all plugins. 它将像处理所有插件一样解决此问题。 You also need to deploy the plugin to whatever pluginRepository you're using. 您还需要将插件部署到您使用的任何pluginRepository。

For example, I have a plugin, which is defined in its pom as: 例如,我有一个插件,在其pom中定义为:

<groupId>org.mine</groupId>
<artifactId>my-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin>

which is what it seems you already have. 这似乎是您已经拥有的。

Then, run mvn deploy. 然后,运行mvn deploy。

In the project you want to use the plugin is, add to your pom: 在您要使用插件的项目中,将其添加到pom中:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.mine</groupId>
      <artifactId>my-maven-plugin</artifactId>
      <version>1.0</version>
    </plugin>
    ...
  </plugins>
  ...
</build>

Finally, make sure you have the repository you deployed to set up in your pom.xml in the tag. 最后,确保您已部署要在的pom.xml中设置的存储库。

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

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