依赖项与 Spring Boot 中提供的范围一起打包
我想在没有Javafaker依赖性的情况下打包Spring Boot Jar。我正在使用Javafaker依赖性,并希望仅在开发时间内将其加载。
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
即使将范围添加为提供的
,JAR也将作为最终JAR文件的一部分打包。我如何在最终构建中排除依赖关系。
I want to package the spring boot jar without the javafaker dependency. I am using the Javafaker dependency and want it to be loaded only during dev time.
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
Even after adding the scope as provided
, the jar is packaged as part of the final jar file. How can I exclude the dependency in the final build.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来这是 Spring Boot 团队有意
从 https://github 完成的。 com/spring-projects/spring-boot/issues/413 :
提供的作用域 jar 的打包是有意为之的。原因是许多开发人员习惯于添加像提供的 servlet-api 这样的东西。由于不会有 servlet 容器来实际“提供”依赖项,因此我们将其打包在 JAR 中。
确保它不会最终出现在 JAR 文件中的唯一方法是使用 spring boot maven插件配置并将其排除在那里。
It seems that this is done intentionally by the Spring Boot team
From https://github.com/spring-projects/spring-boot/issues/413 :
The packaging of provided scoped jars is intentional. The reason for this is that many developers are used to adding things like servlet-api as provided. Since there won’t be a servlet container to actually “provide” the dependency we package it inside the JAR.
The only way to ensure that it doesn't end up in your JAR file is to use the spring boot maven plugin configuration and exclude it there.