我正在使用Spring Boot实现一个微服务,它真的很好,它构建了一个"胖罐"打包所有必需的依赖项。
但是,它是我甚至不使用的打包依赖项,例如:我使用的是Cassandra数据库,但由于Spring-starter依赖性,它仍然在100多个其他数据库中打包MongoDB依赖项,导致 24 MB jar文件!
我在这里做错了吗? 是否可以告诉Maven排除所有未实际使用的依赖项?
编辑:我错了,它只包含必要的依赖项,无视这个问题。
这是pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- Cassandra -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
UPDATE :这是依赖:树
[INFO] com.test.project:dataloader:jar:0.0.1
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.1.8.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:1.1.8.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:4.0.7.RELEASE:compile
[INFO] | | \- org.springframework:spring-aop:jar:4.0.7.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.1.8.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:1.1.8.RELEASE:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.7:compile
[INFO] | | +- org.slf4j:log4j-over-slf4j:jar:1.7.7:compile
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] | | \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.7.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.13:compile
[INFO] +- org.springframework.data:spring-data-cassandra:jar:1.1.0.RELEASE:compile
[INFO] | +- org.springframework.data:spring-cql:jar:1.0.4.RELEASE:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.0.7.RELEASE:compile
[INFO] | | +- org.springframework:spring-tx:jar:4.0.7.RELEASE:compile
[INFO] | | +- org.apache.cassandra:cassandra-all:jar:2.0.6:compile
[INFO] | | | +- org.xerial.snappy:snappy-java:jar:1.0.5:compile
[INFO] | | | +- net.jpountz.lz4:lz4:jar:1.2.0:compile
[INFO] | | | +- com.ning:compress-lzf:jar:0.8.4:compile
[INFO] | | | +- commons-cli:commons-cli:jar:1.1:compile
[INFO] | | | +- commons-codec:commons-codec:jar:1.2:compile
[INFO] | | | +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] | | | +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.3:compile
[INFO] | | | +- org.antlr:antlr:jar:3.2:compile
[INFO] | | | | \- org.antlr:antlr-runtime:jar:3.2:compile
[INFO] | | | | \- org.antlr:stringtemplate:jar:3.2:compile
[INFO] | | | | \- antlr:antlr:jar:2.7.7:compile
[INFO] | | | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] | | | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile
[INFO] | | | +- jline:jline:jar:1.0:compile
[INFO] | | | +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] | | | +- com.github.stephenc.high-scale-lib:high-scale-lib:jar:1.1.2:compile
[INFO] | | | +- edu.stanford.ppl:snaptree:jar:0.1:compile
[INFO] | | | +- org.mindrot:jbcrypt:jar:0.3m:compile
[INFO] | | | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | | | +- com.addthis.metrics:reporter-config:jar:2.1.0:compile
[INFO] | | | | \- org.hibernate:hibernate-validator:jar:5.0.3.Final:compile
[INFO] | | | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | | | +- org.jboss.logging:jboss-logging:jar:3.1.1.GA:compile
[INFO] | | | | \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] | | | +- com.thinkaurelius.thrift:thrift-server:jar:0.3.3:compile
[INFO] | | | | \- com.lmax:disruptor:jar:3.0.1:compile
[INFO] | | | +- net.sf.supercsv:super-csv:jar:2.1.0:compile
[INFO] | | | +- log4j:log4j:jar:1.2.17:compile
[INFO] | | | +- org.apache.thrift:libthrift:jar:0.9.1:compile
[INFO] | | | | +- org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[INFO] | | | | \- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO] | | | +- org.apache.cassandra:cassandra-thrift:jar:2.0.6:compile
[INFO] | | | +- com.github.stephenc:jamm:jar:0.2.5:compile
[INFO] | | | \- io.netty:netty:jar:3.6.6.Final:compile
[INFO] | | +- com.google.guava:guava:jar:15.0:compile
[INFO] | | \- org.liquibase:liquibase-core:jar:3.0.8:compile
[INFO] | +- org.springframework:spring-expression:jar:4.0.7.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile
[INFO] | +- com.datastax.cassandra:cassandra-driver-dse:jar:2.0.4:compile
[INFO] | | \- com.datastax.cassandra:cassandra-driver-core:jar:2.0.4:compile
[INFO] | | \- com.codahale.metrics:metrics-core:jar:3.0.2:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.7:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.1.8.RELEASE:test
[INFO] +- junit:junit:jar:4.11:compile
[INFO] +- org.mockito:mockito-core:jar:1.9.5:test
[INFO] | \- org.objenesis:objenesis:jar:1.0:test
[INFO] +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] \- org.springframework:spring-test:jar:4.0.7.RELEASE:test
答案 0 :(得分:1)
我怀疑spring-data-cassandra(或其他)依赖项有一个父级,它涵盖了所有类型的其他dbs,并且它们被拉了。您可以使用<exclusion>
代码
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.1.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>..</groupId>
<artifactId>..</artifactId>
</exclusion>
</exclusions>
</dependency>