【问题标题】:dependency is packaged with provided scope in spring boot在 spring boot 中使用提供的范围打包依赖项
【发布时间】:2022-12-18 21:52:27
【问题描述】:

我想打包没有javafaker依赖的spring boot jar。我正在使用 Javafaker 依赖项并希望它仅在开发期间加载。

<dependency>
  <groupId>com.github.javafaker</groupId>
  <artifactId>javafaker</artifactId>
  <version>1.0.2</version>
  <scope>provided</scope>
</dependency>

即使在将范围添加为 provided 之后,jar 也会打包为最终 jar 文件的一部分。如何排除最终构建中的依赖项。

【问题讨论】:

    标签: spring-boot spring-boot-maven-plugin maven-dependency


    【解决方案1】:

    看来这是Spring Boot团队有意为之

    来自https://github.com/spring-projects/spring-boot/issues/413

    提供的 scoped jar 的包装是有意的。这样做的原因是许多开发人员习惯于添加提供的 servlet-api 之类的东西。由于不会有 servlet 容器实际“提供”我们将其打包在 JAR 中的依赖项。

    确保它不会出现在您的 JAR 文件中的唯一方法是使用 spring boot maven 插件配置并将其排除在外。

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude>
                                <groupId>com.github.javafaker</groupId>
                                <artifactId>javafaker</artifactId>
                            </exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 2019-07-15
      • 2017-04-25
      • 2016-05-28
      • 2011-12-31
      • 2016-01-04
      • 2018-07-30
      • 2017-01-15
      • 1970-01-01
      相关资源
      最近更新 更多