I'm trying to start using Kotlin DSL with gradle in the project with the following restrictions:
- Project has different modules (moreover: sometimes these modules use different plugins, however if two projects uses the same plugin then version of the plugins are the same).
- Project只有内部公司存储库(例如,我们不直接使用jcenter,而是使用代理).
Groovy的特点是:
- 一些常见的配置项被排除在单独的脚本之外.请判断下面的例子.
- Gradle modules include these files.
As a result (just based on my example):
- 我们不需要在每个模块中添加相同的代码行.
- The most of projects have difference just with dependency list.
I tried to reproduce the same with Gralde KTS and received the following difficulties:
- I'm unable to apply plugin in the include file and use it in the module. In this case I receive compilation error (because plugin types are not added into the module script).
- 我无法将常量提取到每个脚本(包括根
build.gradle.kts
)中常用的东西.对于Groovy,我可以只使用springBootVersion
这样的变量,但是对于Kotlin脚本,我必须在每个模块文件中创建相同的属性. - Precompiled script plugins does not work without public repositories access (e.g. I'm unable to configure common script file with idea "just use default embedded Kotlin Script version, download all dependencies from these urls: ...".
包括文件示例:
apply plugin: 'kotlin'
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
Gradle module sample:
apply from: "${rootDir}/gradle/include/kotlin-common-include.gradle"
dependencies {
compile project(':my.project.libraries.common')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
Questions:
- 如何将所有常用常量(如依赖项版本)放入单独的文件中,只需使用
springBootVersion
或Constants.springBootVersion
之类的编译时判断就可以包含它们? - 如何提取应用于包含脚本的插件(以避免Gradle模块脚本过载)?
- How can I use precompiled script plugins without public global repositories access?
Additional links: