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