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')
}
A Spring Boot application is typically built into a single executable JAR archive. It contains all dependencies inside, packaged as nested JARs. Likewise, a Spring Boot project is usually built as an executable JAR file by a provided maven plugin that does all the dirty work.
FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.
In one word, we call it a methodology where an entire Spring Boot application is built into a single executable Jar archive and includes all the dependencies, packaged as nested Jars. The plugins in Maven does all the dirty work and provides you with the FAT Jar, which can be run easily using the command of java -jar.
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() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With