在GradleKotlin中为子项目构建版本目录

x759pob2  于 12个月前  发布在  Kotlin
关注(0)|答案(1)|浏览(183)

我正在将Gradle多模块构建从Groovy迁移到KotlinDSL,我想使用Gradle的静态类型版本目录。

// plugins declared in the settings.gradle.kts

subprojects {

  apply {
    plugin("groovy")
    plugin("java-library")
    plugin("ch.onstructive.gradle.release")
    plugin("ch.onstructive.gradle.codestyle")
  }

  configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.toVersion("17")
    targetCompatibility = JavaVersion.toVersion("17")
  }

  dependencies {

    val annotationProcessor by configurations
    val implementation by configurations

    annotationProcessor(libs.mapstruct.processor) // <-- cannot access the libs here
    implementation(libs.mapstruct) // <-- cannot access the libs here
  }
}

字符串
在我的gradle/libs.versions.toml

[versions]
mapstructVersion = "1.5.5.Final"

[libraries]
mapstruct-processor = { module = "org.mapstruct:mapstruct-processor", version.ref = "mapstructVersion" }
mapstruct = { module = "org.mapstruct:mapstruct", version.ref = "mapstructVersion" }


现在我得到以下错误

Build file 'build.gradle.kts' line: 54

Extension with name 'libs' does not exist. Currently registered extension names: [ext, base, defaultArtifacts, sourceSets, reporting, javaToolchains, java, groovyRuntime, testing, publishing, spotless, micronautSourceSetConfigurer, micronaut, eclipse, graalvmNative]


如何在subprojects闭包的dependencies闭包中使用版本目录?

o2g1uqev

o2g1uqev1#

在这种情况下,可以使用rootProject.libs访问版本目录。

subprojects {

  apply {
    plugin("groovy")
    plugin("java-library")
    plugin("ch.onstructive.gradle.release")
    plugin("ch.onstructive.gradle.codestyle")
  }

  configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.toVersion("17")
    targetCompatibility = JavaVersion.toVersion("17")
  }

  dependencies {

    val annotationProcessor by configurations
    val implementation by configurations

    annotationProcessor(rootProject.libs.mapstruct.processor)    
    implementation(rootProject.libs.mapstruct)
  }
}

字符串

相关问题