Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle building Spring Boot library without Main Class

I am trying to build a Spring Boot/Gradle project and create a jar without a main class. My purpose is that this project is a library that will be pulled in by other projects therefore the library project does not require a main class to run. Unfortunately, no matter what kind of gradle config I write I keep getting errors when I try to build install about not having a main class or not being able to find the bootJar task.

Here's what my gradle file looks like:

plugins {
    id 'org.springframework.boot' version '2.1.7.RELEASE' apply false
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'

dependencyManagement {
    imports {
        mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
    }
}

repositories {
    mavenCentral()
}

jar {
    enabled = true
}

bootJar.dependsOn fooTask

But when I run this I get the following error:

Could not get unknown property 'bootJar' for root project 'foo-library' of type org.gradle.api.Project.

What in my configuration needs to change?

like image 539
Richard Avatar asked Aug 26 '19 16:08

Richard


People also ask

Can I run Spring Boot without main class?

When Spring boot application starts: If we define no main class, Spring Boot will search for the main class in the class path. It will fail, we there is no main class or we have multiple classes with the main method.

Can Gradle be used with Spring Boot?

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

Disable bootJar in your build.gradle

bootJar {
   enabled = false
}
like image 140
Jonathan JOhx Avatar answered Sep 17 '22 19:09

Jonathan JOhx