在多模块Maven项目的子模块上定义Maven插件会给我们“找不到插件”错误。 尤其是如果我们有一个多模块项目,并且只想在一个特定模块中应用Maven插件,则此错误会经常发生。

假设我们有一个看起来像这样的多模块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><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>
</project>

本能地将插件(例如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中找到“未找到插件”相关推荐

  1. Android Studio升级中的“未找到默认活动”

    本文翻译自:"Default Activity Not Found" on Android Studio upgrade I upgraded IntelliJ Idea from ...

  2. 更新数据时出错——所有记录中均未找到搜索关键字

    出错环境:windows server 2003 enterprise sp2+Access2000+iis6 出错情况:打开页面修改数据后保存时出现错误:所有记录中均未找到搜索关键字 出错原因:Mi ...

  3. Access所有记录中均未找到搜索关键字

    一个excel表要导入数据到Access表中. 使用导入向导,到最后完成时总会提示"所有记录中均未找到搜索关键字",很多人遇到这个问题,大多都是因为索引字段问题导致. 我这肯定不是 ...

  4. 【U8】固定资产结账提示“在对应所需名称或序数的集合中,未找到项目”

    固定资产结账时报错: 在对应所需名称或序数的集合中,未找到项目,自动备份本月帐套失败,如果继续进行月末结账则不能恢复到月末结账前状态. 解决方法: 是卡片样式的问题,查看 fa_model 表,每一个 ...

  5. maven 插件未找到_防止在多模块Maven中找到“未找到插件”

    maven 插件未找到 在多模块Maven项目的子模块上定义Maven插件会给我们一个"未找到插件"错误. 特别是如果我们有一个多模块项目,并且只想在一个特定模块中应用Maven插 ...

  6. maven_防止在多模块Maven中找到“未找到插件”

    maven 在多模块Maven项目的子模块上定义Maven插件会给我们"找不到插件"错误. 特别是如果我们有一个多模块项目,并且只想在一个特定模块中应用Maven插件,则此错误会经 ...

  7. linux中wget未找到命令

    在装数据库的时候发现无法使用wget命令,提示未找到命令,如图所示 那是因为没有安装wget,输入命令:yum -y install wget 如下图所示,wget及其依赖将会被安装 安装完成后就可以 ...

  8. 计算机未能找到网络,无线适配器未找到,未找到网络适配器

    Intel My WiFi软件能够实现手机通过电脑共享无线上网,但是在win7系统下安装Intel My WiFi之后,在任务栏的右下角总会提示"未找到适配器",出现这样的原因是因 ...

  9. linux中mail未找到命令,mail命令使用在linux系统中输入mail,就进入了收件箱错误的是()...

    工商行政管理机制是指在现行体制框架内工商行政管理部门()的有机结合体. 用偏光显微镜观察宝石多色性,应在:(). 由不同功能的计划构成进度计划系统包括(). 男,48岁.一年来每于剧烈活动时或饱餐后发 ...

最新文章

  1. 什么是操作系统 PV 操作
  2. ZOJ - 3872 Beauty of Array
  3. 长安大学研究生院计算机学院,研究生教育
  4. J2EE技术(三)——JMS
  5. HTML5 API详解(15):History 不刷新也可以实现网页跳转
  6. Cookie篡改攻击
  7. HTML5 Canvas中实现文字链接
  8. 四川首例 “自贡话智能语音识别系统”在检察院投用
  9. matlab中内联,有没有一种方法可以在MATLAB中执行函数内联?
  10. 【转载】Altera官方资料整理
  11. 自动驾驶技术(3)- 高精度地图解决自动驾驶的功能痛点
  12. win7打开xp共享的计算机,win7系统如何访问xp共享打印机_windows7连接xp共享打印机的方法...
  13. 中国最牛天使投资人:30万元投资,回报超50000倍
  14. 用MySQL绘制新年祝福图形_2020年春节,你有哪些与众不同的祝福语?
  15. linux服务器留后门,Linux下留本地后门的两个方法
  16. 内网IT风险管控解决方案
  17. 【数值分析实验MATLAB】数值积分:梯形公式、辛普森公式、复化梯形公式、复化辛普森公式、龙贝格算法、自适应求积方法
  18. 2021-2022学年广州市南武中学七年级第一学期期中考试英语试题
  19. 【总结】搜索引擎の精确搜索法
  20. mysql的reorg_DB2 runstats和reorg操作

热门文章

  1. python常见内置函数
  2. Java标识符与命名规则
  3. 2020蓝桥杯省赛---java---C---3( 跑步训练)
  4. android volley 上传图片 和参数,Android使用Volley实现上传文件功能
  5. OkHttp上传Json嵌套对象
  6. 不同范数下的余弦定理_第06题 | 从源头追溯「余弦定理」amp; 文理科知识点的异同...
  7. python股票自动买卖视频教程_十分钟学会用Python交易股票
  8. java泛型程序设计——约束与局限性
  9. cuba 平台_认识CLI for CUBA平台
  10. 垃圾收集算法,垃圾收集器_确定活动的热点垃圾收集器