如何更好的管理maven依赖包的版本

1、如果你的pom.xml 文件内有很多相同的groupId(这现象spring等大型框架非常常见),你应该用pom中的properties部分,然后引用它们。

比如:

<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
		<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

		<commons-lang3.version>3.4</commons-lang3.version>
		<commons-io.version>2.4</commons-io.version>
		<commons-primitives.version>1.0</commons-primitives.version>

		<spring.version>4.1.6.RELEASE</spring.version>
		<spring-asm.version>3.1.4.RELEASE</spring-asm.version>
		<spring-security-web.version>4.0.0.RELEASE</spring-security-web.version>

		<cglib.verson>3.1</cglib.verson>

		<logback-classic.version>1.1.3</logback-classic.version>
		<log4j.version>1.2.17</log4j.version>
		<slf4j-api.version>1.7.12</slf4j-api.version>

	</properties>
<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-framework-bom</artifactId>
				<version>${spring.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.opencredo.esper</groupId>
			<artifactId>esper-template</artifactId>
			<version>2.1</version>
			<exclusions>
				<exclusion>
					<groupId>com.espertech</groupId>
					<artifactId>esper</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>slf4j-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-context</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.espertech</groupId>
			<artifactId>esper</artifactId>
			<version>5.2.0</version>
			<exclusions>
				<exclusion>
					<artifactId>log4j</artifactId>
					<groupId>log4j</groupId>
				</exclusion>
				<exclusion>
					<artifactId>commons-logging</artifactId>
					<groupId>commons-logging</groupId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.43</version>
		</dependency>

		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>18.0</version>
		</dependency>

		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>${commons-lang3.version}</version>
		</dependency>

		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>${commons-io.version}</version>
		</dependency>
		<dependency>
			<groupId>commons-primitives</groupId>
			<artifactId>commons-primitives</artifactId>
			<version>${commons-primitives.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<exclusions>
				<exclusion>
					<artifactId>commons-logging</artifactId>
					<groupId>commons-logging</groupId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-asm</artifactId>
			<version>${spring-asm.version}</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.14</version>
		</dependency>
		<dependency>
			<groupId>postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>9.1-901-1.jdbc4</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j-api.version}</version>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>${logback-classic.version}</version>
		</dependency>

		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
			<version>${logback-classic.version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>${slf4j-api.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>log4j-over-slf4j</artifactId>
			<version>${slf4j-api.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>

	</dependencies>

2、可视化观察依赖关系

现在的ide,比如spring官方的sts,就自带了可视化查看依赖。

我们也可以用maven dependency插件查看,

[[email protected] esper-2015]$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building esper-2015 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ esper-2015 ---
[INFO] com.doctor:esper-2015:jar:1.0.0-SNAPSHOT
[INFO] +- org.opencredo.esper:esper-template:jar:2.1:compile
[INFO] +- com.espertech:esper:jar:5.2.0:compile
[INFO] |  +- org.antlr:antlr4-runtime:jar:4.1:compile
[INFO] |  |  \- org.abego.treelayout:org.abego.treelayout.core:jar:1.0.1:compile
[INFO] |  \- cglib:cglib-nodep:jar:3.1:compile
[INFO] +- com.alibaba:fastjson:jar:1.1.43:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- commons-primitives:commons-primitives:jar:1.0:compile
[INFO] +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:4.1.6.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.8.5:compile
[INFO] +- org.springframework:spring-asm:jar:3.1.4.RELEASE:compile
[INFO] +- com.alibaba:druid:jar:1.0.14:compile
[INFO] |  +- com.alibaba:jconsole:jar:1.8.0:system
[INFO] |  \- com.alibaba:tools:jar:1.8.0:system
[INFO] +- postgresql:postgresql:jar:9.1-901-1.jdbc4:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] +- org.springframework:spring-test:jar:4.1.6.RELEASE:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.904 s
[INFO] Finished at: 2015-06-13T09:55:09+08:00
[INFO] Final Memory: 15M/205M
[INFO] ------------------------------------------------------------------------
[[email protected] esper-2015]$

上面都可以观察依赖,主要解决jar包依赖冲突现象。排除低版本的jar本。sts支持可视化管理排除。

传递性依赖我们可以用, exclusions and optional aven either by the depending 排除。

时间: 2024-10-19 06:01:06

如何更好的管理maven依赖包的版本的相关文章

maven依赖包下载失败解决办法

原文:http://www    .zuidaima.com/question/2535347150441472.htm maven依赖包下载失败 比如:Missing artifact org.codehaus.jackson:jackson-mapper-asl:jar:1.9.9 这种问题即使使用Project=>Clean来重新Buil项目都不行,因为这个操作是属于项目重新编译,而该问题是依赖包问题,所以只有在依赖包正常的情况下操作才会成功,解决办法就是maven clean 操作步骤如

JsonObject没有fromObject、idea引入maven有红线没依赖、JsonObject maven 依赖包

目录: 1.JsonObject maven 依赖包 2.idea引入maven有红线,没依赖 3.JsonObject没有fromObject \\\\\\\\\\\\\\\\\\\\\\\ 1.JsonObject maven 依赖包 一共就用一个,但是功能全就六个,我也是上网查到的. pom.xml如下: <dependencies> <!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib --> &l

导入spark程序的maven依赖包时,无法导入,报错Unable to import maven project: See logs for details

问题:导入spark程序的maven依赖包时,无法导入,且报错:0:23 Unable to import maven project: See logs for details 2019-08-23 00:34:05,140 [ 747292] WARN - #org.jetbrains.idea.maven - Cannot reconnect. java.lang.RuntimeException: Cannot reconnect. at org.jetbrains.idea.maven

flutter如何使用配置文件pubspec.yaml(位于项目根目录)来管理第三方依赖包

官方文档 在软件开发中,很多时候有一些公共的库或SDK可能会被很多项目用到,因此,将这些代码单独抽到一个独立模块,然后哪个项目需要使用时再直接集成这个模块,便可大大提高开发效率.很多编程语言或开发工具都支持这种“模块共享”机制,如Java语言中这种独立模块会被打成一个jar包,Android中的aar包,Web开发中的npm包等.为了方便表述,我们将这种可共享的独立模块统一称为“包”( Package). 一个APP在实际开发中往往会依赖很多包,而这些包通常都有交叉依赖关系.版本依赖等,如果由开

Maven依赖排除及版本统一

Maven依赖排除及版本统一 依赖排除 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.0.0.RELEASE</version> <!-- 依赖排除 --> <exclusions> <exclusion> <groupId>

IntelliJ IDEA更新maven依赖包

问题: IntelliJ IDEA自动载入Maven依赖的功能很好用,但有时候会碰到问题,导致pom文件修改却没有触发自动重新载入的动作,此时需要手动强制更新依赖. 方法: 方法一: (1)右键单击项目: (2)在弹出菜单中选择Maven|Reimport菜单项. 或者,IDEA将通过网络自动下载相关依赖,并存放在Maven的本地仓库中.另外,可以将Maven的刷新设置为自动,配置方法为: (1)单击File|Setting菜单项,打开Settings选项卡: (2)在左侧的目录树中,展开Mav

maven依赖包无法更新xiaz

在IDEA工程中导入已存在的module时,按默认设置,直到完成导入,结果所有的外部依赖包都无法更新下载,即使是更新了setting.xml配置文件信息,依旧是不能更新下载依赖包,现将具体的操作过程和修改策略分步骤说明: (1)导入已存在的module过程中配置环境信息,如下图所示:  在导入的步骤中可以看到上图按钮,点击它,弹出如下对话框:                           图1 上图中可以给导入的模块设置特定的maven版本.setting.xml文件和本地制品库目录. (

JSON对应的maven依赖包

常用有三种json解析jackson.fastjson.gson. jackson依赖包 <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</

解决Ubuntu在安装某个软件时依赖包的版本过高问题

在安装mysql时: 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3.  sudo apt-get install libmysqlclient-dev 第三步时:某个依赖包安装不上 出现: zlib1g-dev : Depends: zlib1g (= 1:1.2.8.dfsg-2ubuntu4) but 1:1.2.8.dfsg-2ubuntu4.1 is to be installedE: Una