Skip to content

Commit

Permalink
Merge pull request #391 from nebula-plugins/dannyt/spring-boot-use-ma…
Browse files Browse the repository at this point in the history
…in-distribution

Use main distribution for Spring Boot 2+ applications
  • Loading branch information
DanielThomas authored Jan 29, 2021
2 parents 19c9eb3 + 3ef0204 commit be75252
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ class OspackageApplicationSpringBootPlugin implements Plugin<Project> {
throw new IllegalStateException("The 'org.springframework.boot' plugin must be applied before applying this plugin")
}

// Spring Boot 2.0 configures an distribution that has everything we need
// Spring Boot 2.0 configures distributions that have everything we need
OspackageApplicationExtension extension = project.extensions.getByType(OspackageApplicationExtension)
if (project.distributions.findByName('boot') != null) {
extension.distribution = 'boot'
// See https://github.com/spring-projects/spring-boot/issues/12232
// Use the main distribution and configure it to have the same baseName as the boot distribution
project.jar {
enabled = true
}
project.afterEvaluate {
project.distributions {
boot {
main {
if(GradleVersion.current().baseVersion < GradleVersion.version('6.0').baseVersion) {
baseName = "${project.distributions.main.baseName}-boot"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ package com.netflix.gradle.plugins.application
import com.google.common.base.Throwables
import com.netflix.gradle.plugins.deb.Scanner
import nebula.test.IntegrationSpec
import org.junit.Rule
import org.junit.contrib.java.lang.system.ProvideSystemProperty
import spock.lang.Unroll

import java.util.jar.Manifest
import java.util.zip.ZipFile

class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {

//TODO: remove this once @Optional is removed from https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/application/CreateBootStartScripts.java#L33
@Rule
public final ProvideSystemProperty myPropertyHasMyValue = new ProvideSystemProperty("ignoreDeprecations", "true")

def 'plugin throws exception if spring-boot plugin not applied'() {
buildFile << """
${applyPlugin(OspackageApplicationSpringBootPlugin)}
Expand Down Expand Up @@ -86,7 +76,7 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {

@Unroll
def 'application shows up in deb for boot #bootVersion'() {
final applicationDir = distribution.isEmpty() ? moduleName : "$moduleName-$distribution"
final applicationDir = "$moduleName-boot"
final startScript = "./opt/${applicationDir}/bin/${moduleName}"
buildFile << buildScript(bootVersion, null)

Expand All @@ -100,31 +90,23 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {
final moduleJarName = "./opt/${applicationDir}/lib/${moduleName}.jar"

scanner.getEntry(startScript).mode == fileMode

[
startScript,
"./opt/${applicationDir}/bin/${moduleName}.bat",
moduleJarName].each {
assert scanner.getEntry("${it}").isFile()
}

final moduleJar = new ZipFile(scanner.getEntryFile(moduleJarName))
final manifest = new Manifest(moduleJar.getInputStream(moduleJar.getEntry('META-INF/MANIFEST.MF')))
manifest.getMainAttributes().getValue('Main-Class') == 'org.springframework.boot.loader.JarLauncher'

!scanner.dataContents.keySet().find { tarArchiveEntry ->
tarArchiveEntry.name.endsWith('.jar') && tarArchiveEntry.name != moduleJarName
}
!scanner.controlContents.containsKey('./postinst')

where:
bootVersion | distribution | fileMode
'2.4.2' | 'boot' | 0755
bootVersion | fileMode
'2.4.2' | 0755
}

@Unroll
def 'application runs for boot #bootVersion'() {
final applicationDir = distribution.isEmpty() ? moduleName : "$moduleName-$distribution"
final applicationDir = "$moduleName-boot"
final startScript = file("build/install/$applicationDir/bin/$moduleName")

buildFile << buildScript(bootVersion, startScript)
Expand All @@ -136,8 +118,8 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {
result.standardOutput.contains('Hello Integration Test')

where:
bootVersion | distribution
'2.4.2' | 'boot'
bootVersion | _
'2.4.2' | _
}

@Unroll
Expand All @@ -155,7 +137,7 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {
runTasksSuccessfully('buildDeb')

then:
final appName = distribution.isEmpty() ? 'myapp' : "myapp-$distribution"
final appName = "myapp-boot"
final archivePath = file("build/distributions/test_0_all.deb")
final scan = new Scanner(archivePath)

Expand All @@ -170,7 +152,7 @@ class OspackageApplicationSpringBootPluginLauncherSpec extends IntegrationSpec {
}

where:
bootVersion | distribution | fileMode
'2.4.2' | 'boot' | 493
bootVersion | fileMode
'2.4.2' | 493
}
}

0 comments on commit be75252

Please # to comment.