In my project, a generated executable jar contains every jar within the BOOT-INF/lib directory twice with identical file names. This pretty much doubles the size of the final jar.
The issue is not present in 2.4.0-M1 of the Maven-Plugin. The issue is present since 2.4.0-M2. So, M4 still contains it.
The produced executable jar is functional. Just the file size is doubled.
My library usage:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0-M4</version> <!-- M2-M4 add lib jars twice; M1 is fine -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<!--<finalName>${jarName}</finalName>-->
<layout>JAR</layout>
<classifier>spring-boot</classifier>
<mainClass>${mainClass}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Comment From: philwebb
I'm having trouble replicating this issue. Could you please share a sample project that shows the problem?
Comment From: Ahli
Project where I encounter this issue: https://github.com/Ahli/Galaxy-Observer-UI/tree/master/tools/interfaceBuilder
I will try and reduce this to a small standalone project demonstrating the issue.
Comment From: philwebb
I'm manged to build that project after running mvn install -DskipTests
I don't see any duplicates. Running unzip -l target/compile.jar | sort | uniq -c
shows a count of 1
for all jars.
Is there any trick to getting the duplicate entries? What operating system are you using?
Comment From: Ahli
My environment: Win 10 20H2, JDK 15, Maven 3.5.3, IntelliJ IDEA 2020.3EAP
Here are the jars generated for me (placed in a single zip): https://www.dropbox.com/s/vz1gj1brakt33pr/spring_issue23801.zip?dl=1
Using 7zip, the jars inside BOOT-INF\lib\ are listed as duplicates. Extracting the zip asks for these files to be overwritten. The expected jar size would be approx 56mb (as created with M1). The jar it generates is approx 112mb.
Comment From: philwebb
I think I see the duplicates. They're in compile-spring-boot.jar
not compile.jar
.
Comment From: philwebb
A standard project from start.spring.io with the following plugin config replicates it:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Comment From: Ahli
The issue is not present when layering is disabled.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0-M4</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<layers>
<enabled>false</enabled> <!-- prevents duplicated jars in BOOT-INF/lib/ in 2.4.0-M2 to M4 -->
</layers>
<layout>JAR</layout>
<classifier>spring-boot</classifier>
<mainClass>${mainClass}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Layering was enabled by default between M1 and M2 (between 29th June and 14th August 2020).
Commit History: https://github.com/spring-projects/spring-boot/commits/master/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven Commit that enabled layering by default: https://github.com/spring-projects/spring-boot/commit/41f5ba9077f01b16a3c6fd0b543ddbac566f7e2f#diff-9621a7691c90b1bf3c0b6cdebd10f29dbd8a3fd27aef00b8357b44725ed90804
Comment From: wilkinsona
All of the launcher classes are also packaged twice. Once beneath /
and once beneath /BOOT-INF/classes/
.
Comment From: wilkinsona
The launcher classes and the contents of BOOT-INF/lib
are also duplicated with 2.3.4. This is the configuration I used:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<classifier>spring-boot</classifier>
</configuration>
</execution>
</executions>
</plugin>
The duplication of the launcher classes seems to be unrelated to layers as it also occurs with layers disabled.