My Question is: Why does the jar-creation work with gradlew build, while I see "Task :jar SKIPPED" when I click on jar in intellij's gradle window ? And how can I fix it in IntelliJ ?
( yesterday I failed in maven with "no main manifest attribute in .... .jar )
You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.
In this tutorial, we will show you how to use Gradle build tool to create a single Jar file with dependencies. Tools used : Gradle 2.0.
The result JAR will be created in build/libs/ directory by default.
This is because Springboot Gradle plugin will create a bootJar
task and by default will disable jar
and war
tasks, as described here: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#packaging-executable-and-normal
So you need to execute bootJar
task , from the IDE. When executing gradlew build
, the tasks bootJar
gets automatically executed, due to tasks dependencies created by the plugin.
When running task build
(from console or IDE), you can see the tasks executed by Gradle depending on tasks dependencies, e.g.:
> Task :backend:compileJava
> Task :backend:processResources
> Task :backend:classes
> Task :backend:bootJar ## <== this is the task register by Springboot plugin, which produces the "Fat/executable" jar
> Task :backend:jar SKIPPED ## <== task disabled by Springboot plugin
> Task :backend:assemble
> Task :backend:processTestResources
> Task :backend:testClasses
> Task :backend:test
> Task :backend:check
> Task :backend:build
For your remark
the jar runs fine, it finds the main class - even without jar manifest attribute in build.gradle
The Springboot plugin will automatically configure this for you, see : https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#packaging-executable-configuring-main-class
EDIT 27-05-2021
Starting from Springboot 2.5, the jar
is not disabled by default anymore. see more details in release notes here
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