背景:在spring项目搭建练习过程,使用exclusion标签排除spring-boot-starter-jpa里面的hibernate-core依赖,然后发现并未排除成功
项目环境:
spring-boot-parent 3.3.5
maven-compiler-plugin 3.10.1&3.13.0两个版本都试过
jdk 17
maven依赖如下
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 项目基本信息隐藏 -->
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.15.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
运行命令行
mvn clean install -DskipTests
打包成功查看依赖树
mvn dependency:tree
结果如下
--------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dependency:3.6.1:tree (default-cli) @ redis-test ---
[INFO] org.example:redis-test:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:3.3.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:3.3.5:compile
[INFO] | | +- org.springframework:spring-aop:jar:6.1.14:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.22.1:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:3.3.5:compile
[INFO] | | +- com.zaxxer:HikariCP:jar:5.1.0:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:6.1.14:compile
[INFO] | +- org.hibernate.orm:hibernate-core:jar:6.5.3.Final:compile
[INFO] | | +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] | | +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] | | +- io.smallrye:jandex:jar:3.1.2:runtime
[INFO] | | +- jakarta.inject:jakarta.inject-api:jar:2.0.1:runtime
[INFO] | | \- org.antlr:antlr4-runtime:jar:4.13.0:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:3.3.5:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:3.3.5:compile
[INFO] | | +- org.springframework:spring-orm:jar:6.1.14:compile
[INFO] | | +- org.springframework:spring-context:jar:6.1.14:compile
[INFO] | | | +- org.springframework:spring-expression:jar:6.1.14:compile
[INFO] | | | \- io.micrometer:micrometer-observation:jar:1.13.6:compile
[INFO] | | | \- io.micrometer:micrometer-commons:jar:1.13.6:compile
[INFO] | | +- org.springframework:spring-tx:jar:6.1.14:compile
[INFO] | | +- org.springframework:spring-beans:jar:6.1.14:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:2.0.16:compile
[INFO] | \- org.springframework:spring-aspects:jar:6.1.14:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.6.15.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.5.3.Final:compile
[INFO] | +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.14.19:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final:compile
[INFO] | +- org.jboss:jandex:jar:2.4.2.Final:compile
[INFO] | +- com.fasterxml:classmate:jar:1.7.0:compile
[INFO] | +- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:5.1.2.Final:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | \- org.glassfish.jaxb:jaxb-runtime:jar:4.0.5:compile
[INFO] | \- org.glassfish.jaxb:jaxb-core:jar:4.0.5:compile
[INFO] | +- org.eclipse.angus:angus-activation:jar:2.0.2:runtime
[INFO] | +- org.glassfish.jaxb:txw2:jar:4.0.5:compile
[INFO] | \- com.sun.istack:istack-commons-runtime:jar:4.1.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:3.3.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.3.5:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:3.3.5:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:3.3.5:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:3.3.5:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.5.11:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.5.11:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.23.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.23.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:2.0.16:compile
[INFO] | | \- org.yaml:snakeyaml:jar:2.2:compile
[INFO] | +- io.lettuce:lettuce-core:jar:6.3.2.RELEASE:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.114.Final:compile
[INFO] | | +- io.netty:netty-handler:jar:4.1.114.Final:compile
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.114.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.114.Final:compile
[INFO] | | | +- io.netty:netty-transport-native-unix-common:jar:4.1.114.Final:compile
[INFO] | | | \- io.netty:netty-codec:jar:4.1.114.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.114.Final:compile
[INFO] | | \- io.projectreactor:reactor-core:jar:3.6.11:compile
[INFO] | | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] | \- org.springframework.data:spring-data-redis:jar:3.3.5:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:3.3.5:compile
[INFO] | +- org.springframework:spring-oxm:jar:6.1.14:compile
[INFO] | \- org.springframework:spring-context-support:jar:6.1.14:compile
[INFO] +- com.h2database:h2:jar:2.2.224:runtime
[INFO] +- org.projectlombok:lombok:jar:1.18.34:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:3.3.5:test
[INFO] +- org.springframework.boot:spring-boot-test:jar:3.3.5:test
[INFO] +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.3.5:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.9.0:test
[INFO] +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.2:compile
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:2.1.3:compile
[INFO] +- net.minidev:json-smart:jar:2.5.1:test
[INFO] | \- net.minidev:accessors-smart:jar:2.5.1:test
[INFO] | \- org.ow2.asm:asm:jar:9.6:test
[INFO] +- org.assertj:assertj-core:jar:3.25.3:test
[INFO] +- org.awaitility:awaitility:jar:4.2.2:test
[INFO] +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.10.5:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.10.5:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | | +- org.junit.platform:junit-platform-commons:jar:1.10.5:test
[INFO] | | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.10.5:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.10.5:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.10.5:test
[INFO] +- org.mockito:mockito-core:jar:5.11.0:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.14.19:test
[INFO] | \- org.objenesis:objenesis:jar:3.3:test
[INFO] +- org.mockito:mockito-junit-jupiter:jar:5.11.0:test
[INFO] +- org.skyscreamer:jsonassert:jar:1.5.3:test
[INFO] | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] +- org.springframework:spring-core:jar:6.1.14:compile
[INFO] | \- org.springframework:spring-jcl:jar:6.1.14:compile
[INFO] +- org.springframework:spring-test:jar:6.1.14:test
[INFO] \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
可以看到jpa里面的hibernate-core:6.5.3-Final依然存在,排除不成功
为了避免是我idea的问题,然后测试了另外一套版本
环境配置如下
spring-boot-parent 2.7.12
maven-compiler-plugin 3.10.1
jdk 17
maven依赖如下
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 项目基本信息隐藏 -->
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-money</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
同样maven打包构建在查看依赖树,结果如下
org.example:redis-demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.7.12:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:2.7.12:compile
[INFO] | | +- org.springframework:spring-aop:jar:5.3.27:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.7:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.7.12:compile
[INFO] | | +- com.zaxxer:HikariCP:jar:4.0.3:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:5.3.27:compile
[INFO] | +- jakarta.transaction:jakarta.transaction-api:jar:1.3.3:compile
[INFO] | +- jakarta.persistence:jakarta.persistence-api:jar:2.2.3:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.7.12:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:2.7.12:compile
[INFO] | | +- org.springframework:spring-orm:jar:5.3.27:compile
[INFO] | | +- org.springframework:spring-context:jar:5.3.27:compile
[INFO] | | | \- org.springframework:spring-expression:jar:5.3.27:compile
[INFO] | | +- org.springframework:spring-tx:jar:5.3.27:compile
[INFO] | | +- org.springframework:spring-beans:jar:5.3.27:compile
[INFO] | | \- org.springframework:spring-core:jar:5.3.27:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.3.27:compile
[INFO] | \- org.springframework:spring-aspects:jar:5.3.27:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.3.7.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.4.3.Final:compile
[INFO] | +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] | +- org.javassist:javassist:jar:3.23.1-GA:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.12.23:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final:compile
[INFO] | +- org.jboss:jandex:jar:2.0.5.Final:compile
[INFO] | +- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | +- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.7.12:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.7.12:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:2.7.12:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.7.12:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.7.12:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.12:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.12:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.30:compile
[INFO] | +- org.springframework.data:spring-data-redis:jar:2.7.12:compile
[INFO] | | +- org.springframework.data:spring-data-keyvalue:jar:2.7.12:compile
[INFO] | | +- org.springframework:spring-oxm:jar:5.3.27:compile
[INFO] | | \- org.springframework:spring-context-support:jar:5.3.27:compile
[INFO] | \- io.lettuce:lettuce-core:jar:6.1.10.RELEASE:compile
[INFO] | +- io.netty:netty-common:jar:4.1.92.Final:compile
[INFO] | +- io.netty:netty-handler:jar:4.1.92.Final:compile
[INFO] | | +- io.netty:netty-resolver:jar:4.1.92.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.1.92.Final:compile
[INFO] | | +- io.netty:netty-transport-native-unix-common:jar:4.1.92.Final:compile
[INFO] | | \- io.netty:netty-codec:jar:4.1.92.Final:compile
[INFO] | +- io.netty:netty-transport:jar:4.1.92.Final:compile
[INFO] | \- io.projectreactor:reactor-core:jar:3.4.29:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] +- redis.clients:jedis:jar:2.9.1:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] | \- org.apache.commons:commons-pool2:jar:2.11.1:compile
[INFO] +- com.h2database:h2:jar:2.1.214:runtime
[INFO] +- org.projectlombok:lombok:jar:1.18.30:compile
[INFO] +- org.joda:joda-money:jar:1.0.1:compile
[INFO] \- org.jadira.usertype:usertype.core:jar:6.0.1.GA:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.6.15.Final:compile
[INFO] \- org.jadira.usertype:usertype.spi:jar:6.0.1.GA:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
可以看到starter-jpa里面的hibernate-core依赖被成功排除;
弄了半天不知道什么原因,看看路过的大佬有没有能指点我下的,欢迎讨论!