Gradle Kotlin DSL:如何使用Typesafe API配置子项目 [英] Gradle Kotlin DSL: how to configure subprojects using typesafe api

查看:110
本文介绍了Gradle Kotlin DSL:如何使用Typesafe API配置子项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

6.1.1级

我一直在尝试使用Kotlin DSL以类型安全的方式转换项目的Gradle文件,但到目前为止失败了.我所有的项目都是Java的多项目构建.想法是分解/删除子模块的通用配置(无论是在根模块的子项目"块中还是在我不在乎的单独"kts"文件中). 官方文档指出不可能对'subprojects'进行类型安全并应用(from ='shared.gradle.kts')(

I have been trying to convert my projects' Gradle files using Kotlin DSL in a type-safe manner but so far failed. All my projects are multi-project builds in Java. The idea is to factorize/deduplicate the common configurations of the submodules (whether in the 'subprojects' block of the root module or in a separate 'kts' file I don't care). The official documentation states that it is not possible to have type-safe with 'subprojects' and apply(from = 'shared.gradle.kts') (https://docs.gradle.org/current/userguide/kotlin_dsl.html).

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

It works as below but it is rather anoying:


plugins {
    idea
    eclipse
}

subprojects {
    apply(plugin = "java")

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

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

Is there a way to factorise the module configurations for all the submodules in a type-safe manner ? If not... does gradle plan to allow it ?

推荐答案

等级6.1.1 类型安全的模型访问器读取:

只有主项目构建脚本和预编译的项目脚本插件具有类型安全的模型访问器.初始化脚本,设置脚本,脚本插件没有. 这些限制将在将来的Gradle版本中删除.

无论未来版本"是什么意思,而跨-配置项目内容如下:

Whatever "future release" might mean ...while Cross-configuring projects reads:

跨项目配置是一种机制,您可以通过该机制从另一个项目的构建脚本中配置一个项目.一个常见的示例是在根项目构建脚本中配置子项目时. 采用这种方法意味着您将无法对插件贡献的模型元素使用类型安全的访问器.相反,您将不得不依赖字符串文字和标准的Gradle API.

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:如何使用Typesafe API配置子项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆