Skip to content

Commit 948bafa

Browse files
committed
Repackage kotlin-module metadata beneath BOOT-INF/classes
Closes gh-15890
1 parent 3a6d15a commit 948bafa

File tree

2 files changed

+19
-1
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src

2 files changed

+19
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ public JarArchiveEntry transform(JarArchiveEntry entry) {
380380
return null;
381381
}
382382
if ((entry.getName().startsWith("META-INF/")
383-
&& !entry.getName().equals("META-INF/aop.xml"))
383+
&& !entry.getName().equals("META-INF/aop.xml")
384+
&& !entry.getName().endsWith(".kotlin-module"))
384385
|| entry.getName().startsWith("BOOT-INF/")
385386
|| entry.getName().equals("module-info.class")) {
386387
return entry;

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,23 @@ public void moduleInfoClassRemainsInRootOfJarWhenRepackaged() throws Exception {
675675
}
676676
}
677677

678+
@Test
679+
public void kotlinModuleMetadataMovesBeneathBootInfClassesWhenRepackaged()
680+
throws Exception {
681+
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
682+
this.testJarFile.addFile("META-INF/test.kotlin-module",
683+
this.temporaryFolder.newFile("test.kotlin-module"));
684+
File source = this.testJarFile.getFile();
685+
File dest = this.temporaryFolder.newFile("dest.jar");
686+
Repackager repackager = new Repackager(source);
687+
repackager.repackage(dest, NO_LIBRARIES);
688+
try (JarFile jarFile = new JarFile(dest)) {
689+
assertThat(jarFile.getEntry("META-INF/test.kotlin-module")).isNull();
690+
assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/test.kotlin-module"))
691+
.isNotNull();
692+
}
693+
}
694+
678695
private File createLibrary() throws IOException {
679696
TestJarFile library = new TestJarFile(this.temporaryFolder);
680697
library.addClass("com/example/library/Library.class",

0 commit comments

Comments
 (0)