Spring Boot + Gradle: how to build executable jar

I created a project with all the sources you provided. Running "gradle build" from terminal, switching to /build/libs and then running "java -jar artifactname" works just fine.

Have you tried to clean and recompile? Which Version of Gradle are you using?


I just recently tried a Spring boot application with 2.1.4.Release with Gradle build.

I ran the following command from the directory in Windows CMD.

gradlew clean build

(upon required JDK8 installed in the system), I was able to see the JAR generated under,

<project-directory>/build/libs/<project-name-version.jar>

Hope this helps though older question.

Reference:

enter image description here


In Boot 2.x, the bootJar and bootWar tasks are responsible for packaging the application.

The bootJar task is responsible for creating the executable jar file. This is created automatically once the java plugin is applied.

In case the executable jar/war file is not generated run the below gradle task manually.

$./gradlew bootJar

Similarly, bootWar generates an executable war file and gets created once the war plugin is applied.

We can execute the bootWar task using:

$./gradlew bootWar

Note that for Spring Boot 2.x, we need to use Gradle 4.0 or later.


In spring boot you can directly create executable jar file by

springBoot { 
    executable = true 
}

Please try

jar{
    baseName = 'myapp' 
    version = 'version'
}

It will create jar with name myapp-version.jar Do ./myapp-version.jar from command line.it will execute

Refer following link for more info. https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html