【发布时间】:2019-07-15 17:05:30
【问题描述】:
我想构建 jar 文件库而不包含依赖项,因为它们将位于将使用该库的应用程序的类路径中。我为此使用 maven scope - provided 并且所有依赖项都被排除在外,但仍然很少。我发现它们来自 spring-boot-starter-webflux。为什么会这样?我应该怎么做才能摆脱它们?
这里是依赖示例
<dependencies>
<!-- Nevertheless provided scope some jars from this dependency
are in compiled jar file. Why ? -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
仅具有这一依赖关系的示例项目位于 https://github.com/pavelmorozov/MavenProvidedTest/blob/master/pom.xml
空编译的项目 jar 大小超过 5 兆字节。
更新在JF Meier的建议下,我尝试了mvn dependency:tree,发现两个库的作用域为compile
[INFO] +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.1.3.RELEASE:provided
[INFO] | \- io.projectreactor.netty:reactor-netty:jar:0.8.5.RELEASE:compile
[INFO] | +- io.netty:netty-codec-http:jar:4.1.33.Final:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.33.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.1.33.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.33.Final:compile
[INFO] | | | \- io.netty:netty-resolver:jar:4.1.33.Final:compile
[INFO] | | \- io.netty:netty-codec:jar:4.1.33.Final:compile
[INFO] | +- io.netty:netty-codec-http2:jar:4.1.33.Final:compile
[INFO] | +- io.netty:netty-handler:jar:4.1.33.Final:compile
[INFO] | +- io.netty:netty-handler-proxy:jar:4.1.33.Final:compile
[INFO] | | \- io.netty:netty-codec-socks:jar:4.1.33.Final:compile
[INFO] | \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.33.Final:compile
[INFO] | \- io.netty:netty-transport-native-unix-common:jar:4.1.33.Final:compile
...
[INFO] +- org.springframework:spring-webflux:jar:5.1.5.RELEASE:provided
[INFO] | \- io.projectreactor:reactor-core:jar:3.2.6.RELEASE:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
例如,我看到了一个 POM 文件
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
<version>2.1.3.RELEASE</version>
...
<dependencies>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.8.5.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
现在我仍然不明白为什么其他 Spring Boot 包含的库没有将 scope 覆盖为 compile。这是否意味着这两个库构建错误或出于某种原因以这种方式构建?而且我仍然不清楚如何以简单的方式删除似乎具有覆盖范围的依赖项?
我尝试将版本号放入我的 POM 依赖项中 - 但这没有效果 - 已编译项目 jar 中包含相同的 jar:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.1.3.RELEASE</version>
<scope>provided</scope>
</dependency>
关于父母的最新动态
父 pom 文件 spring-boot-starter-parent 不包含任何 dependencyManagement 部分,但有一个父级 - spring-boot-dependencies - 它确实有 dependencyManagement 部分,但没有提供在那里编译的范围。不过,一些依赖项具有范围导入。我不明白这个导入范围的依赖项是否会对我产生影响。这里的一些示例:
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
...
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bom</artifactId>
<version>${reactor-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...
</dependencies>
</dependencyManagement>
spring-boot-starter-reactor-netty的部分内容我在之前的更新中贴在这里。
更新 Andy Wilkinson 回答只是为了澄清 - jar 中不包含此类依赖项,似乎 spring boot maven 插件在这里以不同的方式工作:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
【问题讨论】:
标签: maven spring-boot spring-webflux