spring-bootgradle

Executable Spring Boot 2 jar


I try to install my Spring Boot application. As first step I try to create an executable jar as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

However if I extend my gradle script (I'm using gradle 4.4) with the lines:

springBoot {
    executable = true
}

Then the build fails with an error:

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\spring\app\build.gradle' line: 15

* What went wrong:
A problem occurred evaluating root project 'app'.
> Could not find method springBoot() for arguments [build_3mwux4us8m2jn9yfcogqkbm4y$_run_closure1@506b241f] on root project 'app' of type org.gradle.api.Project.

My build script is the following:

buildscript {
    ext {
        springBootVersion = '2.0.0.M6'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

springBoot {
    executable = true
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


group = 'com.test'
version = '0.0.3'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url 'https://repo.spring.io/libs-release' }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-validation')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.data:spring-data-envers:2.0.2.RELEASE')
    compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

Solution

  • You've linked to the reference documentation for Spring Boot 1.x, but you're using Spring Boot 2.x where the Gradle plugin has been updated quite extensively. It now has its own, separate reference documentation.

    In that reference documentation, it describes how to create a fully executable jar file that includes the prepended launch script:

    Spring Boot provides support for fully executable archives. An archive is made fully executable by prepending a shell script that knows how to launch the application. On Unix-like platforms, this launch script allows the archive to be run directly like any other executable or to be installed as a service.

    To use this feature, the inclusion of the launch script must be enabled:

    bootJar {
        launchScript()
    }