首页 > 解决方案 > 尽管在 spring-boot-maven-plugin 中配置了排除,但日志依赖项仍包含在 lib 文件夹中

问题描述

编辑:原来我只是不擅长找东西。更改之前的战争没有这些库,并且原始 .war(重新打包之前)已经包含它们。所以问题出在其他地方,spring-boot-maven-plugin 与它无关。仍然不知道它们来自哪里,因为我也尝试过简单地删除我找到的依赖项,但是哦,好吧,看看我的第一句话。

我正在努力使我的公司软件作为 Spring Boot 应用程序运行。由于我们的战争可能部署在各种不同的环境中,例如 SAP Cloud Platform,因此日志库不应包含在 lib 文件夹中以防止冲突。但是,无论我的排除有多么具体,一些日志库(特别是 jul-to-slf4j、log4j-api 和 log4j-to-self4j)总是在我的 lib 文件夹中。其他库(测试所需或必须包含在类文件中的两个库)被正确排除。

我已经尝试将标签设置为特定的库以及排除整个组。在此之后,我尝试简单地排除依赖项本身,但是在 mvn dependency:tree 告诉我它们不再存在之后它们仍然以某种方式出现。

这是插件配置:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>
                    repackage
                </goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>de.firm.integration.BaseSpringConfiguration</mainClass>
        <excludes>
            <exclude>
                <groupId>de.firm.integration</groupId>
                <artifactId>eis-generator-odata-api</artifactId>
            </exclude>
            <exclude>
                <groupId>de.firm.integration</groupId>
                <artifactId>eis-admin-ui</artifactId>
            </exclude>
            <exclude>
                <groupId>org.slf4j</groupId>
                <artifactId>jul-to-slf4j</artifactId>
            </exclude>
            <exclude>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
            </exclude>
            <exclude>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-jul</artifactId>
            </exclude>
            <exclude>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclude>
            <exclude>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-to-slf4j</artifactId>
            </exclude>
        </excludes>
    </configuration>
</plugin>

我希望我构建的战争不再将这些日志库包含在我的 WEB-INF/lib 文件夹中。相反,他们一直被包括在内。

标签: javaspringspring-bootlog4jslf4j

解决方案


试试这个...在 WAR 中包含和排除文件

通过使用 <packagingIncludes> 和 <packagingExcludes> 配置参数,可以在 WAR 文件中包含或排除某些文件。

因此,您基本上只需在这些标签中指定WEB-INF/lib/log4j -.jar、WEB-INF/lib /jul- .jar即可排除所有以 log4j 和 jul 开头的包。

<plugins>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.3</version>
    <configuration>
      <packagingExcludes>
       WEB-INF/lib/log4j-*.jar, WEB-INF/lib/jul-*.jar
      </packagingExcludes>
    </configuration>
  </plugin>
</plugins>


推荐阅读