简体   繁体   中英

How to setup a multi-module gradle project with Quarkus?

A multi-module gradle project with the Quarkus plugin applied in the root build.gradle.kts fails at the :quarkusBuild step with a NoSuchElementException :

> Task :quarkusBuild FAILED
building quarkus jar

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':quarkusBuild'.
> java.util.NoSuchElementException

The root build.gradle.kts is like so:

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

plugins {
    kotlin("jvm") version "1.3.72"
    id("io.quarkus") version "1.9.1.Final"
}

group = "org.example"
version = "1.0-SNAPSHOT"

allprojects {
    repositories {
        mavenCentral()
    }
}

subprojects {
    
    apply {
        plugin("kotlin")
    }

    dependencies {
        implementation(kotlin("stdlib"))
    }
}

However move the line id("io.quarkus") version "1.9.1.Final" to the sub projects' build.gradle.kts and the build succeeds. It seems that the quarkus build step is run where the plugin is declared, rather than where it is actually applied.

Ideally I want to declare the plugin once in the root, then apply it to subprojects only, not have it execute against the root project, where there's obviously nothing to build.

Any ideas?

You need to add apply false

plugins {
    kotlin("jvm") version "1.3.72" apply false
    id("io.quarkus") version "1.9.1.Final" apply false
}

https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl

Your build also assumes that every sub-module will be a Kotlin module which may or may not be true. You can do something a little more like this to apply specific configurations to specific tasks:

subprojects { subproject ->
    subproject.tasks.withType(JavaCompile).configureEach {
        sourceCompatibility = JavaVersion.VERSION_11
    }
    subproject.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11
        }
    }
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM