gpt4 book ai didi

Gradle Kotlin DSL : how to configure subprojects using typesafe api

转载 作者:行者123 更新时间:2023-12-02 02:40:03 26 4
gpt4 key购买 nike

Gradle 6.1.1

我一直在尝试使用 Kotlin DSL 以类型安全的方式转换我项目的 Gradle 文件,但到目前为止都失败了。我所有的项目都是用 Java 构建的多项目。这个想法是分解/删除子模块的公共(public)配置(无论是在根模块的“子项目” block 中还是在我不关心的单独的“kts”文件中)。官方文档指出,“子项目”和 apply(from = 'shared.gradle.kts') ( https://docs.gradle.org/current/userguide/kotlin_dsl.html ) 不可能具有类型安全。

它的工作原理如下,但相当烦人:


plugins {
idea
eclipse
}

subprojects {
apply(plugin = "java")

dependencies {
"implementation"("com.google.guava:guava:28.1-jre")
//...
}
}

有没有办法以类型安全的方式分解所有子模块的模块配置?如果不是... gradle 是否计划允许它?

最佳答案

Gradle 6.1.1 Type-safe model accessors阅读:

Only the main project build scripts and precompiled project script plugins have type-safe model accessors. Initialization scripts, settings scripts, script plugins do not. These limitations will be removed in a future Gradle release.

无论“ future 版本”可能意味着什么......而 Cross-configuring projects阅读:

Cross project configuration is a mechanism by which you can configure a project from another project’s build script. A common example is when you configure subprojects in the root project build script. Taking this approach means that you won’t be able to use type-safe accessors for model elements contributed by the plugins. You will instead have to rely on string literals and the standard Gradle APIs.

关于 Gradle Kotlin DSL : how to configure subprojects using typesafe api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60179864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com