Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bootRepackage depends on jar not war when using Gradle War Plugin

Without Gradle War Plugin, bootRepackage task depends on jar task but with Gradle War Plugin, it depends on war task.

How can I change it to depend on jar task even though I'm using Gradle War Plugin?

UPDATE:

I'm using war task to create a war file including documents to be deployed to a documentation server and I want to use bootRepackaged jar file to provide a service. My war task depends on asciidoctor task which depends on test task (I'm using Spring REST Docs.) but I don't want to run asciidoctor task or test task when using bootRepackage task.

I solved my problem with the following setup:

ext {
    mainClassName = 'com.izeye.throwaway.Application'
}

task myBootRepackage(type: BootRepackage, dependsOn: jar) {
}

but I'm not sure this is a good practice.

This is a sample project having the above configuration:

https://github.com/izeye/spring-boot-throwaway-branches/tree/war

like image 740
Johnny Lim Avatar asked Oct 30 '15 09:10

Johnny Lim


People also ask

How do you add spring dependencies in build gradle?

We can add Spring Boot support into our Gradle project by applying the Spring Boot Gradle plugin. We can select the preferred Spring Boot version by setting the version of the Spring Boot Gradle plugin. This means that we don't have to set the dependency versions of the Spring Boot dependencies.

What is bootRun in gradle?

The Spring Boot gradle plugin provides the bootRun task that allows a developer to start the application in a “developer mode” without first building a JAR file and then starting this JAR file. Thus, it's a quick way to test the latest changes you made to the codebase.

What does spring boot gradle plugin do?

The Spring Boot Gradle Plugin provides Spring Boot support in Gradle. It allows you to package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by spring-boot-dependencies . Spring Boot's Gradle plugin requires Gradle 6.8, 6.9, or 7.


1 Answers

You should have been able to do this:

bootRepackage {
    withJarTask jar
}

While this correctly causes the jar task's jar to be repackaged, it doesn't remove the dependency on the war task. This is another symptom of this Spring Boot issue.

Until this issue has been resolved, the approach that you've taken – declaring your own BootRepackage task and manually configuring the tasks that it depends upon – is your best option.

like image 161
Andy Wilkinson Avatar answered Sep 28 '22 03:09

Andy Wilkinson