简体   繁体   English

如何使用 Quarkus 设置多模块 gradle 项目?

[英]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 :在根build.gradle.kts应用 Quarkus 插件的多模块 gradle 项目在:quarkusBuild步骤失败,并出现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:build.gradle.kts是这样的:

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.但是将行id("io.quarkus") version "1.9.1.Final"到子项目的build.gradle.kts并且构建成功。 It seems that the quarkus build step is run where the plugin is declared, rather than where it is actually applied.似乎 quarkus 构建步骤是在声明插件的地方运行的,而不是实际应用的地方。

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您需要添加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 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.您的构建还假设每个子模块都是 Kotlin 模块,这可能是也可能不是。 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
        }
    }
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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