Maven Dependency Exclusion does not work anymore for war archive since version 2.5.0
.
If i downgrade to version 2.4.7
, exclusion of dependencies is correct during repackage
Maven goal.
In think the root cause is this commit : https://github.com/spring-projects/spring-boot/commit/152698f2b23168908ce45721cdbb0d1c0e5dd280#diff-e7a76a5f4e121a18180b454ce4290ca7fc458584efcc82309730c57c73762080R187
Comment From: mbhave
@antoine777 We have an open issue for fixing exclusions with WAR files. AFAIK it hasn't work at all yet so I am a bit surprised that it used to work for you in 2.4. Could you provide a sample that we can run to reproduce the working behavior in 2.4 and the issue you're seeing in 2.5?
Comment From: antoine777
In fact, i need to configure exclusions in 2 maven plugins to achieve my goal
- maven-war-plugin (packagingExcludes
option)
- spring-boot-maven-plugin (excludes
option)
Project sample :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my</groupId>
<artifactId>war-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.8</version>
</dependency>
<dependency>
<groupId>batik</groupId>
<artifactId>batik-util</artifactId>
<version>1.6-1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>WEB-INF/lib/spring-tx-*.jar,WEB-INF/lib/batik-ext-*.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.7</version>
<configuration>
<mainClass>org.apereo.cas.web.CasWebApplication</mainClass>
<excludes>
<!-- exclude pom dependency -->
<exclude>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</exclude>
<!-- exclude transitive dependency -->
<exclude>
<groupId>batik</groupId>
<artifactId>batik-ext</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
C:\Users\...\war-project>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< my:war-project >---------------------------
[INFO] Building war-project 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ war-project ---
[INFO] my:war-project:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework:spring-tx:jar:5.3.8:compile
[INFO] | +- org.springframework:spring-beans:jar:5.3.8:compile
[INFO] | \- org.springframework:spring-core:jar:5.3.8:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.3.8:compile
[INFO] \- batik:batik-util:jar:1.6-1:compile
[INFO] \- batik:batik-gui-util:jar:1.6-1:compile
[INFO] \- batik:batik-ext:jar:1.6-1:compile
[INFO] \- xml-apis:xmlParserAPIs:jar:2.0.2:compile
In version 2.4.7
, spring-tx
and batik-ext
are removed from final springboot war
Comment From: wilkinsona
Thanks. The use of packagingExcludes
was the key difference here. https://github.com/spring-projects/spring-boot/issues/15808 has now been fixed and the problem no longer occurs with 2.5.2-SNAPSHOT, even without the <packagingExcludes>
.