Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle: Task :jar SKIPPED while I get my jar with gradlew build

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 ?

  • Just created something with spring initializer and loaded the project in intellij as it is. ( it is org.springframework.boot, .. 'org.springframework.boot:spring-boot-starter-web')
  • I wonder about Task :jar SKIPPED ( nor jar created )
  • and than I discovered that I get the jar when I start from console.
  • ( and the jar runs fine, it finds the main class - even without jar manifest attribute in build.gradle)

( yesterday I failed in maven with "no main manifest attribute in .... .jar )

like image 431
sKnak Avatar asked Jun 13 '20 14:06

sKnak


People also ask

Does Gradle build run all tasks?

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.

Does Gradle build create jar?

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.

Where is JAR file after Gradle build?

The result JAR will be created in build/libs/ directory by default.


1 Answers

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 jaris not disabled by default anymore. see more details in release notes here

like image 74
M.Ricciuti Avatar answered Oct 22 '22 22:10

M.Ricciuti