maven 插件未找到_防止在多模块Maven中找到“未找到插件”
生活随笔
收集整理的這篇文章主要介紹了
maven 插件未找到_防止在多模块Maven中找到“未找到插件”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
maven 插件未找到
在多模塊Maven項目的子模塊上定義Maven插件會給我們一個“未找到插件”錯誤。 特別是如果我們有一個多模塊項目,并且只想在一個特定模塊中應用Maven插件,則此錯誤會經常發生。
假設我們有一個看起來像這樣的多模塊root pom。
本能地,我們將插件(例如tomcat7)添加到此特定模塊module2 ,就像這樣。
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><artifactId>maven-plugin-multimodule-module2</artifactId><packaging>war</packaging><parent><groupId>com.jdriven.blog</groupId><artifactId>maven-plugin-multimodule</artifactId><version>0.1-SNAPSHOT</version><relativePath>../</relativePath></parent><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><!-- This is where our specific configuration goes --></configuration></plugin></plugins></build> </project>在多模塊root pom上運行命令mvn tomcat7:help時,出現以下錯誤:
[ERROR] No plugin found for prefix 'tomcat7' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories解決方案非常簡單:我們在多模塊root pom的pluginManagement部分中指定插件。
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.jdriven.blog</groupId><artifactId>maven-plugin-multimodule</artifactId><version>0.1-SNAPSHOT</version><packaging>pom</packaging><modules><module>module1</module> <!-- Module1 is a regular jar --><module>module2</module> <!-- Module2 has tomcat7 plugin configured --></modules><build><!-- In the multi-module root pom, use the pluginManagement to define the version of the maven-plugin --><pluginManagement><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version></plugin></plugins></pluginManagement></build></project>并且在我們特定的模塊module2我們清除了插件的版本,因為它已在多模塊root pom(父代)中定義。
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><artifactId>maven-plugin-multimodule-module2</artifactId><packaging>war</packaging><parent><groupId>com.jdriven.blog</groupId><artifactId>maven-plugin-multimodule</artifactId><version>0.1-SNAPSHOT</version><relativePath>../</relativePath></parent><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><!-- No version needed here, it is already defined in the multi-module root pom --><configuration><!-- This is where our specific configuration goes --></configuration></plugin></plugins></build></project>現在,何時可以運行命令mvn tomcat7:help ,不會出現任何錯誤。 我們準備在子模塊上配置插件。
翻譯自: https://www.javacodegeeks.com/2015/03/prevent-no-plugin-found-in-multi-module-maven.html
maven 插件未找到
總結
以上是生活随笔為你收集整理的maven 插件未找到_防止在多模块Maven中找到“未找到插件”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win7电脑中资源管理器打不开怎么办?
- 下一篇: 改变数据类型的装饰器_用装饰器改变收藏