From 6093af640801c9a9f8f661c860e93d9346113178 Mon Sep 17 00:00:00 2001 From: Martin Chalupa Date: Tue, 23 Feb 2021 14:43:14 -0800 Subject: [PATCH] bootJar and jar task output name is the same which can cause overriding and bundling wrong jar in debian --- .../OspackageApplicationSpringBootPlugin.groovy | 7 +++++++ ...plicationSpringBootPluginLauncherSpec.groovy | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPlugin.groovy b/src/main/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPlugin.groovy index 87f65ff8..d5aee0b8 100644 --- a/src/main/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPlugin.groovy +++ b/src/main/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPlugin.groovy @@ -68,6 +68,13 @@ class OspackageApplicationSpringBootPlugin implements Plugin { enabled = true } project.afterEvaluate { + project.bootJar { + if(GradleVersion.current().baseVersion < GradleVersion.version('6.0').baseVersion) { + classifier = "boot" + } else { + archiveClassifier = "boot" + } + } project.distributions { main { if(GradleVersion.current().baseVersion < GradleVersion.version('6.0').baseVersion) { diff --git a/src/test/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPluginLauncherSpec.groovy b/src/test/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPluginLauncherSpec.groovy index 471e4c93..4a9899e0 100644 --- a/src/test/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPluginLauncherSpec.groovy +++ b/src/test/groovy/com/netflix/gradle/plugins/application/OspackageApplicationSpringBootPluginLauncherSpec.groovy @@ -23,6 +23,9 @@ import org.junit.Rule import org.junit.contrib.java.lang.system.ProvideSystemProperty import spock.lang.Unroll +import java.util.jar.JarEntry +import java.util.jar.JarFile + class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec { @Rule @@ -67,6 +70,8 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec { dependencies { implementation 'org.springframework.boot:spring-boot-starter:$bootVersion' } + + bootJar.mustRunAfter jar ospackage { packageName = 'test' @@ -87,7 +92,7 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec { buildFile << buildScript(bootVersion, null) when: - runTasksSuccessfully('buildDeb') + runTasksSuccessfully('build', 'buildDeb') then: final archivePath = file("build/distributions/test_0_all.deb") @@ -103,6 +108,10 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec { assert scanner.getEntry("${it}").isFile() } + //make sure we don't have boot jar in debian + def jarFile = new JarFile(scanner.getEntryFile(moduleJarName)) + ! isBootJar(jarFile) + !scanner.controlContents.containsKey('./postinst') where: @@ -110,6 +119,12 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec { '2.4.2' | 0755 } + private boolean isBootJar(JarFile jarFile) { + jarFile.entries().any { + it.name.contains("BOOT-INF") + } + } + @Unroll def 'application runs for boot #bootVersion'() { final applicationDir = "$moduleName-boot"