Vmxes
Vmxes

Reputation: 2755

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')
}

Upvotes: 7

Views: 6989

Answers (3)

yu yang Jian
yu yang Jian

Reputation: 7171

Use example spring 2 here, then mvnw clean package generate jar in \target folder.

Upvotes: 0

Andy Wilkinson
Andy Wilkinson

Reputation: 116091

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()
}

Upvotes: 15

Bauer Marius
Bauer Marius

Reputation: 180

Try executing following gradle tasks manually:

  • gradlew jar
  • gradlew bootRepackage

afterwards you should have your bundled fat Jar. (Thats how i solved it)

Upvotes: 0

Related Questions