maven的一些优化经验

背景

最近在优化一个系统的jar包依赖的问题,pom相关的问题,项目在install后报一堆黄色的警告,虽然不影响打包部署发布使用(maven已经很友好地帮忙给处理了),但一堆黄色的感叹号放那着实让人洁癖癌复发,太难受,消灭他们吧。

操作

问题1:

有许多无用的依赖

解决:通过“mvn dependency:analyze”命令扫描分析下,会指出所有无用的包(也不能以扫描的结果为准,删除后需要结合系统验证),和有声明问题的包。可参考我的这篇博客:https://blog.csdn.net/u010730870/article/details/103344410

问题2:

dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.***:***:jar

解决:报这个警告是说你的pom里有重复声明的包坐标,检查下剩一个就好

问题3:

'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.***:***:jar -> version 1.0.3.20180101 vs 1.0.1.20180102 @ line 123, column 16

解决:这个是说同一个包引入了两个不同的版本。方案1:一般服务包都向下兼容,留最新版本的包即可;方案2:要是未兼容好,必须引两个包,那么在子模块中引用时把版本号也指定上,不要直接继承父模块,因为maven不知道你要引的是哪一个。此时如果引入两个包后有冲突,那么还要exclusions排除掉冲突的部分

问题4

'dependencies.dependency.scope' for com.***-bom:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 413, column 11

解决:这个是说在子模块中使用scope为import时使用错了,单独的dependencies.dependency中scope的值必须为[provided, compile, runtime, test, system]中的一个,若需要子模块引入一份单独的type=pom的坐标集,需要保证dependencies外层有dependencyManagement层,要是不想改之前的,那么就在之前dependencies外边写一层:

<dependencyManagement><dependencies><dependency>****</dependency></dependencies></dependencyManagement>

具体原因见这块,讲的很清楚:https://www.cnblogs.com/huahua035/p/7680607.html。这块主要明白什么是maven的单继承,如何去规避单继承,和为什么要规避单继承

问题5:

Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

解决:这个是说需要把构建项目的maven编码需要设置为utf-8,原因:构建依赖平台(服从)编码。

在pom.xml文件中添加
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值