Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore gradle build of root project for a multi-project Kotlin Spring Boot application?

Background:

I currently have a multi-module (multi-project) application repo. The "root" is not a runnable application. It's merely the source directory where I have a root build.gradle.kts file which holds the dependencies and plugins that are common between all my sub-projects. Each of my sub-projects have their own build.gradle.kts.

So my overall project structure looks sort of like this:

my_root_project
    - gradle
        - wrapper
            - gradle-wrapper.jar
            - gradle-wrapper.properties
    - gradle.build.kts
    - settings.gradle.kts
    - my_nested_project_a
        - src
            - main
                - kotlin
    - my_nested_project_b
        ...

Issue:

Every time I run gradle build, I get an error saying:

> Task :bootJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootJar'.
> Main class name has not been configured and it could not be resolved

However when I run any one of my sub-projects (e.g. build :my_nested_project_a:build), it builds just fine.

Current Gradle Build Files

Here's what I currently have in the "root" gradle.build.kts:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "com.example"
version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

plugins {
    id("org.springframework.boot") version "2.1.8.RELEASE" apply false
    id("io.spring.dependency-management") version "1.0.8.RELEASE" apply false
    kotlin("jvm") version "1.3.50"
    kotlin("plugin.spring") version "1.3.50"
    kotlin("plugin.jpa") version "1.3.50"
    kotlin("plugin.allopen") version "1.3.50"
}

allprojects {
    repositories {
        maven(url = "https://my.company.com/repo/with/all/the/stuff/I/need")
    }

    apply(plugin = "org.jetbrains.kotlin.jvm")
    apply(plugin = "java")
    apply(plugin = "org.springframework.boot")
    apply(plugin = "io.spring.dependency-management")
    apply(plugin = "org.jetbrains.kotlin.plugin.spring")

    dependencies {
        implementation("org.springframework.boot:spring-boot-starter-web")
        implementation("org.jetbrains.kotlin:kotlin-reflect")
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "1.8"
        }
    }
}

NOTE: I'm using apply false on my plugins because I thought it would keep gradle from trying to find a main class when building using gradle build.

What I'm trying to do:

I have a CI pipeline that I'd like to simply run gradle build which should run the build task for all of the sub-projects. However, in that process, I'd like to ignore running the build for the "root" project or bypass it since it's not a runnable application, and just build the sub-projects.

Any help would be greatly appreciated! :)

like image 423
drix Avatar asked Sep 02 '25 16:09

drix


1 Answers

If you want to ignore task bootJar,s o add the following configuration.

bootJar {
    enabled = false
}
like image 84
Jonathan JOhx Avatar answered Sep 04 '25 07:09

Jonathan JOhx