Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle with no main class?

Tags:

java

gradle

Is it possible to use Gradle without specifying a main class? I want to create a library and use gradle to manage my dependencies, and creating a main class doesn't make sense, but I can't seem to find any documents that don't say you need one.

Thanks

like image 728
BrendanMcKee Avatar asked Oct 14 '14 05:10

BrendanMcKee


1 Answers

Looks like you are using spring-boot gradle plugin to create a library, it maybe call task bootRepackage to find main class, that throw some error when the main class not found.

Use bootRepackage.enabled is work for me.

bootRepackage.enabled = false

If you using kotlin DSL like me, try tasks:

tasks.withType<RepackageTask> {
    enabled = false
}

Also:

val bootRepackage by tasks.getting {
    enabled = false
}

I am looking for a better answer on the spring boot gradle plugin, but not found temporarily.

Or, we can just use spring-boot-dependencies with io.spring.dependency-management, they will not append task bootRepackage to our projects.

plugins {
    id("io.spring.dependency-management")
}

dependencyManagement {
    imports { mavenBom("org.springframework.boot:spring-boot-dependencies:X.Y.Z.RELEASE") }
}

But it is not good idea I think.

And, if you want upgrade spring boot version to 2.Y.Z.RELASE, change bootRepackage to bootJar.

like image 60
Mirro Mutth Avatar answered Nov 20 '22 06:11

Mirro Mutth