Maven 插件之 maven-enforcer-plugin 解决冲突重复依赖

目录

      • 0、前言
      • 1、enforcer 是什么
      • 2、能干什么
      • 3、怎么用
      • 4、规则
      • 5、扩展规则
      • 6、使用
      • 7、banDuplicateClasses
      • 8、banDuplicatePomDependencyVersions

0、前言

maven 项目种经常出现 jar 包冲突、重复依赖、无效引用怎么办,maven-enforcer-plugin 了解一下

1、enforcer 是什么

Enforcer is a build rule execution framework
提供了管控一系列环境约束的目标,包括但不限于Maven版本、JDK版本和操作系统家族等多个内置规则以及用户自定义规则。
https://maven.apache.org/enforcer/maven-enforcer-plugin/index.html

2、能干什么

在项目构建时,通过规则来约束项目配置,如jdk 、maven 版本,是否有重复的类,文件编码,文件大小等等,且规则是可以自己扩展的

3、怎么用

https://maven.apache.org/enforcer/maven-enforcer-plugin/usage.html

4、规则

https://maven.apache.org/enforcer/enforcer-rules/index.html

5、扩展规则

https://www.mojohaus.org/extra-enforcer-rules/index.html#

6、使用

pom 中配置如下插件

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-enforcer-plugin</artifactId><version>3.0.0-M3</version><executions><execution><id>enforce-versions</id><goals><goal>enforce</goal></goals><configuration><rules><bannedPlugins><!-- will only display a warning but does not fail the build. --><level>WARN</level><excludes><exclude>org.apache.maven.plugins:maven-verifier-plugin</exclude></excludes><message>Please consider using the maven-invoker-plugin (http://maven.apache.org/plugins/maven-invoker-plugin/)!</message></bannedPlugins><banDuplicateClasses><ignoreClasses><!-- example of ignoring one specific class --><ignoreClass>com.xyz.i18n.Messages</ignoreClass><!-- example of ignoring with wildcards --><ignoreClass>org.apache.commons.logging.*</ignoreClass></ignoreClasses><scopes><scope>compile</scope><scope>provided</scope></scopes><findAllDuplicates>true</findAllDuplicates><ignoreWhenIdentical>true</ignoreWhenIdentical></banDuplicateClasses><requireMavenVersion><version>3.2.0</version></requireMavenVersion><requireJavaVersion><version>1.8</version></requireJavaVersion></rules><fail>false</fail></configuration></execution></executions><dependencies><dependency><groupId>org.codehaus.mojo</groupId><artifactId>extra-enforcer-rules</artifactId><version>1.2</version></dependency></dependencies>
</plugin>

7、banDuplicateClasses

重复类检测用的rule

<banDuplicateClasses><ignoreClasses><!-- example of ignoring one specific class --><ignoreClass>com.xyz.i18n.Messages</ignoreClass><!-- example of ignoring with wildcards --><ignoreClass>org.apache.commons.logging.*</ignoreClass></ignoreClasses><scopes><scope>compile</scope><scope>provided</scope></scopes><findAllDuplicates>true</findAllDuplicates><ignoreWhenIdentical>true</ignoreWhenIdentical>
</banDuplicateClasses>

执行 使用 mvn clean compile 即可
结果输出,可重点关注 Duplicat classes 部分

[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-versions) @ tet-app ---
[INFO] artifact com.test.maven.test1:com.test.mavne.test1.contract: checking for updates from nexus-public-snapshots
[INFO] artifact com.test.maven.test1:com.test.mavne.test1.contract: checking for updates from nexus
[INFO] Adding ignore: module-info
[INFO] Adding ignore: META-INF/versions/*/module-info
[INFO] Adding ignore: com.xyz.i18n.Messages
[INFO] Adding ignore: org.apache.commons.logging.*
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:
Duplicate classes found:Found in:org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.34:providedorg.glassfish:javax.el:jar:3.0.0:compileDuplicate classes:javax/el/LambdaExpression.classjavax/el/ValueExpression.classjavax/el/ExpressionFactory.classjavax/el/MapELResolver.classjavax/el/ELClass.classjavax/el/PropertyNotFoundException.classjavax/el/FunctionMapper.classjavax/el/ELResolver.classjavax/el/BeanNameResolver.classjavax/el/BeanNameELResolver.classjavax/el/CompositeELResolver.classjavax/el/ELManager.classjavax/el/EvaluationListener.classjavax/el/ResourceBundleELResolver.classjavax/el/ListELResolver.classjavax/el/BeanELResolver$BeanProperty.classjavax/el/ArrayELResolver.classjavax/el/MethodInfo.classjavax/el/StandardELContext.classjavax/el/VariableMapper.classjavax/el/ValueReference.classjavax/el/MethodExpression.classjavax/el/ELProcessor.classjavax/el/TypeConverter.classjavax/el/ELContextEvent.classjavax/el/Expression.classjavax/el/BeanELResolver.classjavax/el/BeanELResolver$1.classjavax/el/ELException.classjavax/el/StaticFieldELResolver.classjavax/el/ELContext.classjavax/el/ImportHandler.classjavax/el/PropertyNotWritableException.classjavax/el/MethodNotFoundException.classjavax/el/BeanELResolver$BeanProperties.classFound in:org.apache.xbean:xbean-reflect:jar:3.7:compileorg.unidal.framework:foundation-service:jar:2.5.0:compileDuplicate classes:org/apache/xbean/recipe/ObjectRecipe$Property.classorg/apache/xbean/recipe/ObjectRecipe$Member.classorg/apache/xbean/recipe/ObjectRecipe.classorg/apache/xbean/recipe/ObjectRecipe$MethodMember.classorg/apache/xbean/recipe/ObjectRecipe$CompoundProperty.classorg/apache/xbean/recipe/ObjectRecipe$AutoMatchProperty.classorg/apache/xbean/recipe/ObjectRecipe$SetterProperty.classorg/apache/xbean/recipe/ObjectRecipe$FieldProperty.classorg/apache/xbean/recipe/ObjectRecipe$FieldMember.classFound in:org.codehaus.plexus:plexus-container-default:jar:1.6:compileorg.unidal.framework:foundation-service:jar:2.5.0:compileDuplicate classes:org/codehaus/plexus/component/builder/XBeanComponentBuilder$RequirementRecipe.classorg/codehaus/plexus/component/builder/XBeanComponentBuilder.classorg/codehaus/plexus/component/builder/XBeanComponentBuilder$1.classorg/codehaus/plexus/component/builder/XBeanComponentBuilder$PlexusConfigurationRecipe.classFound in:javax.servlet:servlet-api:jar:2.5:compileorg.apache.tomcat.embed:tomcat-embed-core:jar:8.5.34:providedDuplicate classes:javax/servlet/http/Cookie.classjavax/servlet/http/HttpSessionContext.classjavax/servlet/http/HttpSessionListener.classjavax/servlet/http/HttpSessionAttributeListener.classjavax/servlet/ServletRequestAttributeListener.classjavax/servlet/ServletRequest.classjavax/servlet/http/HttpUtils.classjavax/servlet/FilterConfig.classjavax/servlet/ServletResponseWrapper.classjavax/servlet/ServletResponse.classjavax/servlet/SingleThreadModel.classjavax/servlet/ServletConfig.classjavax/servlet/http/HttpSessionBindingEvent.classjavax/servlet/ServletOutputStream.classjavax/servlet/ServletContextListener.classjavax/servlet/Filter.classjavax/servlet/Servlet.classjavax/servlet/ServletContextEvent.classjavax/servlet/http/NoBodyOutputStream.classjavax/servlet/UnavailableException.classjavax/servlet/ServletRequestListener.classjavax/servlet/http/HttpServletRequest.classjavax/servlet/ServletContext.classjavax/servlet/FilterChain.classjavax/servlet/http/HttpServletRequestWrapper.classjavax/servlet/http/HttpSessionBindingListener.classjavax/servlet/ServletRequestAttributeEvent.classjavax/servlet/ServletRequestWrapper.classjavax/servlet/ServletRequestEvent.classjavax/servlet/http/HttpServlet.classjavax/servlet/http/HttpServletResponseWrapper.classjavax/servlet/http/HttpSessionActivationListener.classjavax/servlet/http/NoBodyResponse.classjavax/servlet/GenericServlet.classjavax/servlet/ServletException.classjavax/servlet/ServletContextAttributeEvent.classjavax/servlet/http/HttpServletResponse.classjavax/servlet/ServletContextAttributeListener.classjavax/servlet/http/HttpSession.classjavax/servlet/RequestDispatcher.classjavax/servlet/http/HttpSessionEvent.classjavax/servlet/ServletInputStream.classFound in:com.sun.mail:javax.mail:jar:1.4.4:compilejavax.mail:mail:jar:1.4.5:compileDuplicate classes:com/sun/mail/iap/Atom.classcom/sun/mail/util/logging/MailHandler$TailNameFormatter.classcom/sun/mail/pop3/WritableSharedFile.classjavax/mail/Session.classcom/sun/mail/imap/IMAPFolder.classjavax/mail/Multipart.classcom/sun/mail/imap/IMAPFolder$FetchProfileItem.classcom/sun/mail/pop3/POP3Folder.classcom/sun/mail/iap/Response.classcom/sun/mail/imap/IMAPFolder$17.classcom/sun/mail/util/logging/LogManagerProperties$1.classcom/sun/mail/imap/IMAPFolder$8.classjavax/mail/internet/MimeBodyPart.classcom/sun/mail/handlers/text_plain.classcom/sun/mail/handlers/text_xml.classcom/sun/mail/smtp/SMTPTransport$DigestMD5Authenticator.classcom/sun/mail/smtp/DigestMD5.classcom/sun/mail/util/logging/MailHandler.classcom/sun/mail/smtp/SMTPTransport$Authenticator.classcom/sun/mail/imap/protocol/FetchResponse.classcom/sun/mail/smtp/SMTPTransport$NtlmAuthenticator.classjavax/mail/internet/MimePartDataSource.classcom/sun/mail/imap/protocol/Namespaces$Namespace.classcom/sun/mail/auth/Ntlm.classcom/sun/mail/iap/Argument.classcom/sun/mail/pop3/POP3Message.classcom/sun/mail/imap/IMAPFolder$5.classcom/sun/mail/imap/IMAPFolder$14.classjavax/mail/util/ByteArrayDataSource.classcom/sun/mail/imap/MessageLiteral.classjavax/mail/internet/MimeBodyPart$MimePartDataHandler.classcom/sun/mail/pop3/TempFile.classjavax/mail/util/SharedFileInputStream$SharedFile.classcom/sun/mail/imap/IMAPStore.classcom/sun/mail/imap/protocol/RFC822DATA.classcom/sun/mail/imap/IMAPStore$1.classcom/sun/mail/util/MailSSLSocketFactory.classcom/sun/mail/smtp/SMTPTransport.classcom/sun/mail/imap/IMAPFolder$15.classcom/sun/mail/smtp/SMTPTransport$PlainAuthenticator.classcom/sun/mail/util/MimeUtil$1.classjavax/mail/internet/InternetAddress.classcom/sun/mail/imap/IMAPFolder$6.classcom/sun/mail/imap/IMAPBodyPart.classjavax/mail/Transport.classcom/sun/mail/imap/IMAPFolder$7.classcom/sun/mail/imap/protocol/BODYSTRUCTURE.classcom/sun/mail/imap/IMAPFolder$16.classcom/sun/mail/imap/IMAPMessage.classcom/sun/mail/imap/protocol/IMAPProtocol.classcom/sun/mail/util/SocketFetcher$1.classcom/sun/mail/iap/Protocol.classcom/sun/mail/util/logging/LogManagerProperties.classcom/sun/mail/imap/IMAPFolder$1.classcom/sun/mail/imap/IMAPFolder$19.classjavax/mail/util/SharedFileInputStream.classjavax/mail/internet/MimeUtility.classcom/sun/mail/pop3/AppendStream.classcom/sun/mail/imap/IMAPFolder$4.classcom/sun/mail/util/UUEncoderStream.classcom/sun/mail/imap/protocol/IMAPSaslAuthenticator.classjavax/mail/internet/MimeUtility$1NullInputStream.classcom/sun/mail/imap/IMAPFolder$10.classcom/sun/mail/imap/IMAPFolder$13.classcom/sun/mail/imap/IMAPFolder$18.classcom/sun/mail/pop3/POP3Store.classcom/sun/mail/smtp/SMTPTransport$LoginAuthenticator.classcom/sun/mail/imap/protocol/Namespaces.classcom/sun/mail/pop3/Protocol.classcom/sun/mail/imap/IMAPFolder$11.classcom/sun/mail/util/MimeUtil.classcom/sun/mail/imap/IMAPFolder$2.classcom/sun/mail/imap/LengthCounter.classcom/sun/mail/imap/IMAPFolder$12.classcom/sun/mail/imap/IMAPMessage$1FetchProfileCondition.classcom/sun/mail/util/MailSSLSocketFactory$MailTrustManager.classjavax/mail/Folder.classcom/sun/mail/imap/protocol/RFC822SIZE.classcom/sun/mail/imap/IMAPFolder$3.classcom/sun/mail/imap/IMAPFolder$9.classcom/sun/mail/iap/AString.classjavax/mail/internet/MimeMessage.classcom/sun/mail/util/BASE64EncoderStream.classcom/sun/mail/imap/MessageCache.classcom/sun/mail/imap/IMAPStore$ConnectionPool.classjavax/mail/Version.classcom/sun/mail/util/SocketFetcher.classjavax/mail/internet/AsciiOutputStream.classjavax/mail/PasswordAuthentication.class[INFO]
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:prepare-agent (default-prepare-agent) @ test-app ---
[INFO] argLine set to -javaagent:/Users/test/.m2/repository/org/jacoco/org.jacoco.agent/0.7.6.201602180812/org.jacoco.agent-0.7.6.201602180812-runtime.jar=destfile=/Users/test/Develop/IdeaProjects/test-app/target/jacoco.exec -Xms512m -Xmx1024m
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ test-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] Copying 154 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1432 source files to /Users/test/Develop/IdeaProjects/test-app/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:28 min
[INFO] Finished at: 2024-02-26T23:44:18+08:00
[INFO] Final Memory: 68M/664M
[INFO] ------------------------------------------------------------------------

8、banDuplicatePomDependencyVersions

重复的pom 依赖配置 输出结果

[WARNING] Rule 3: org.apache.maven.plugins.enforcer.BanDuplicatePomDependencyVersions failed with message:
Found 2 duplicate dependency declaration in this project:- dependencies.dependency[com.daojia.mobile:com.daojia.mobile.signalbomb.contract:jar] ( 2 times )- dependencyManagement.dependencies.dependency[com.daojia.mobile:com.daojia.mobile.signalbomb.contract:jar] ( 2 times )

更多使用欢迎大家一起来发掘探讨。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/714177.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《AI纪元:幻域探险》

游戏项目名称&#xff1a;《AI纪元&#xff1a;幻域探险》 游戏类型&#xff1a;AI驱动的角色扮演探险游戏&#xff08;RPG&#xff09; 背景设定&#xff1a; 《AI纪元&#xff1a;幻域探险》设定在一个名为“幻域”的广阔虚拟世界。这个世界由高度发达的AI技术支持&#xff0…

SpringCloud-同步异步通讯比较

本文详细探讨了同步通讯和异步通讯在信息传递中的区别&#xff0c;以及它们分别带来的优势和不足。通过对支付流程的案例分析&#xff0c;突显了同步通讯可能面临的阻塞和服务依赖问题&#xff0c;而异步通讯通过引入事件驱动模式和消息代理&#xff08;Broker&#xff09;成功…

SQL Server 开发环境配置教程(SSMS+SQL Prompt)

背景 记录一下 SQL Server 常用开发软件 体验了各种数据库IDE(DBeaver、Navicat、DataGrip)之后综合下来还是感觉 SSMSSQL Prompt 对于 SQL Server 最好用&#xff0c;所以在此记录一下配置过程 数据库可视化管理工具SSMS 官方下载地址&#xff1a; https://learn.microsoft…

Java基础数据结构之栈

一.什么是栈 栈是一种特殊的线性表&#xff0c;它只允许在固定的一端进行元素的添加与使用&#xff0c;且遵循先进后出的原则。添加取用元素的一端称为栈顶&#xff0c;另一端称为栈底。出栈和入栈都是操作栈顶元素 二.栈的模拟实现 栈的底层是一个数组 这是里面的成员变量以…

智能汽车加速车规级存储应用DS2431P+TR 汽车级EEPROM 存储器IC

DS2431PT&R是一款1024位1-Wire EEPROM芯片&#xff0c;由四页存储区组成&#xff0c;每页256位。数据先被写入一个8字节暂存器中&#xff0c;经校验后复制到EEPROM存储器。该器件的特点是&#xff0c;四页存储区相互独立&#xff0c;可以单独进行写保护或进入EPROM仿真模式…

第2章 线性代数

目录 1. 标量、向量、矩阵和张量2. 矩阵和向量相乘3. 单位矩阵和逆矩阵4. 线性相关和生成子空间5. 范数6. 特殊类型的矩阵和向量7. 特征分解8. 奇异值分解9. Moore-Penrose伪逆10. 迹运算11. 行列式 1. 标量、向量、矩阵和张量 标量&#xff08;scalar&#xff09;&#xff1a;…

【 C++ 】特殊类设计

1、请设计一个类&#xff0c;不能被拷贝 拷贝只会出现在两个场景中&#xff1a;拷贝构造函数以及赋值运算符重载&#xff0c;因此想要让一个类禁止拷贝&#xff0c;只需让该类不能调用拷贝构造函数以及赋值运算符重载即可。在C98和C11都有相对应的方法来解决此问题&#xff0c…

ssm172旅行社管理系统的设计与实现

** &#x1f345;点赞收藏关注 → 私信领取本源代码、数据库&#x1f345; 本人在Java毕业设计领域有多年的经验&#xff0c;陆续会更新更多优质的Java实战项目希望你能有所收获&#xff0c;少走一些弯路。&#x1f345;关注我不迷路&#x1f345;** 一 、设计说明 1.1 研究…

day03-Vue-Element

一、Ajax 1 Ajax 介绍 1.1 Ajax 概述 概念&#xff1a;Asynchronous JavaScript And XML&#xff0c;异步 的 JavaScript 和 XML。 作用&#xff1a; 数据交换&#xff1a;通过 Ajax 可以给服务器发送请求&#xff0c;并获取服务器响应的数据。异步交互&#xff1a;可以在 不…

Java教程:SpringBoot项目如何对接Nacos实现服务发现治理,配置管理

–Nacos大家都知道&#xff0c;不懂的可以去官网或者网上查阅一下&#xff0c;本次给大家讲解一下如何在SpringBoot项目中引入Nacos服务来进行服务治理与发现&#xff0c;配置管理等&#xff0c;在微服务当中是必不可少的&#xff0c;各个模块之间可以通过Feign远程调用&#x…

物联网主机:为智能交通赋能

物联网&#xff08;IoT&#xff09;技术的发展为智能交通领域带来了许多创新的解决方案。而在物联网应用中&#xff0c;物联网主机起着关键的作用。本文将为大家介绍一款名为E6000的物联网主机&#xff0c;它是一种多协议、多接口的物联网主机&#xff0c;为智能交通系统的建设…

antvX6 - Vue自定义节点,并实现多种画布操作,拖拽、缩放、连线、双击、检索等等

一、 首先 antv x6 分为两个版本 低版本和高版本 我这里是使用的2.0版本 并且搭配了相关插件 例如&#xff1a;画布的图形变换、地图等 个人推荐 2.0版本&#xff0c;高版本配置多&#xff0c;可使用相关插件多&#xff0c;但是文档描述小&#xff0c;仍在更新&#xff0c; 低…

小d和图片压缩

题目描述 小ddd和她对象小红去海洋馆玩了&#xff0c;但是由于小ddd拍照技术不好&#xff0c;他对象说把她拍的像嘎子&#xff01; 小ddd看了看&#xff0c;发现是小红最近长痘痘了&#xff0c;于是他为了讨小红开心&#xff0c;让痘痘看不见&#xff0c;自学了图像压缩这个技…

装饰器模式 详解 设计模式

装饰器模式 它允许你在不改变对象结构的情况下&#xff0c;动态地将新功能附加到对象上。 结构&#xff1a; 抽象组件&#xff08;Component&#xff09;&#xff1a;定义了原始对象和装饰器对象的公共接口或抽象类&#xff0c;可以是具体组件类的父类或接口。具体组件&…

固定排班计划

目录 1.按发车时间排序。 2.排班日期默认当天时间。 3.编辑不可修改线路和排班日期。 4.线路、车号、司机是否匹配&#xff0c;不匹配不可入库&#xff08;和其他表比&#xff09;&#xff0c;线路、发车时间、司机、车号、日期、上下行相同不可入库&#xff08;和自己表比…

GO语言学习笔记(与Java的比较学习)(一)

GO的优缺点&#xff1a; 此处引用华为云开发者联盟的一篇文章&#xff1a; GO语言的亮点很明显&#xff1a; GoDoc。 GoDoc的静态语言分析能力很强大&#xff0c;可以直接从代码和注释生成漂亮的文档。这一点区别于其他的类似工具如JavaDoc, PHPDoc或者JSDoc。这些工具需要添加…

如何在群晖Docker运行本地聊天机器人并结合内网穿透发布到公网访问

文章目录 1. 拉取相关的Docker镜像2. 运行Ollama 镜像3. 运行Chatbot Ollama镜像4. 本地访问5. 群晖安装Cpolar6. 配置公网地址7. 公网访问8. 固定公网地址 随着ChatGPT 和open Sora 的热度剧增,大语言模型时代,开启了AI新篇章,大语言模型的应用非常广泛&#xff0c;包括聊天机…

C# Socket通信从入门到精通(21)——TCP发送文件与接收文件 C#代码实现

1、前言 我们在开发上位机软件的过程中经常需要发送文件,本文就是介绍如何利用tcp客户端发送文件、tcp服务器端接收文件,而且本文介绍的方法可以自动发送一个文件夹下的所有子目录以及所有文件,经验来自于实际项目,具备非常有价值的参考意义! 2、发送文件以及C#代码 被发…

LeetCode第48天 买卖股票的最佳时机 买卖股票的最佳时机II 动态规划

121. 买卖股票的最佳时机 class Solution { public:int maxProfit(vector<int>& prices) {// int res 0 ;// int low INT_MAX;// for (int i 0; i < prices.size(); i) {// low min(low, prices[i]);// res max(res, prices[i]-low);// }// return r…

低密度奇偶校验码LDPC(八)——QC-LDPC译码器FPGA设计概要

往期博文 低密度奇偶校验码LDPC&#xff08;一&#xff09;——概述_什么是gallager构造-CSDN博客 低密度奇偶校验码LDPC&#xff08;二&#xff09;——LDPC编码方法-CSDN博客 低密度奇偶校验码LDPC&#xff08;三&#xff09;——QC-LDPC码概述-CSDN博客 低密度奇偶校验码…