diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java index 6a8086f21b..65a4076fb1 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java @@ -115,6 +115,9 @@ class BootZipCopyAction implements CopyAction { try (ZipInputStream in = new ZipInputStream(getClass() .getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) { while ((entry = in.getNextEntry()) != null) { + if (entry.isDirectory() && !entry.getName().startsWith("META-INF/")) { + writeDirectory(entry, out); + } if (entry.getName().endsWith(".class")) { writeClass(entry, in, out); } @@ -125,13 +128,21 @@ class BootZipCopyAction implements CopyAction { } } + private void writeDirectory(ZipEntry entry, ZipOutputStream out) throws IOException { + if (!this.preserveFileTimestamps) { + entry.setTime(GUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES); + } + out.putNextEntry(entry); + out.closeEntry(); + } + private void writeClass(ZipEntry entry, ZipInputStream in, ZipOutputStream out) throws IOException { - byte[] buffer = new byte[4096]; if (!this.preserveFileTimestamps) { entry.setTime(GUtil.CONSTANT_TIME_FOR_ZIP_ENTRIES); } out.putNextEntry(entry); + byte[] buffer = new byte[4096]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java b/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java index befdd65f61..8e74fa4d7c 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java @@ -132,6 +132,7 @@ public abstract class AbstractBootArchiveTests { assertThat(jarFile.getEntry( "org/springframework/boot/loader/LaunchedURLClassLoader.class")) .isNotNull(); + assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull(); } } @@ -146,6 +147,7 @@ public abstract class AbstractBootArchiveTests { assertThat(jarFile.getEntry( "org/springframework/boot/loader/LaunchedURLClassLoader.class")) .isNotNull(); + assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull(); } }