提问人:JDMcMillian 提问时间:1/29/2021 最后编辑:JDMcMillian 更新时间:2/10/2021 访问量:806
如何使用变量拆分基于 kotlin 的大型 Gradle 构建文件?
How do you split large kotlin based Gradle build files with variables?
问:
我有一个很大的gradle.build.kts文件,我正在尝试使用apply(from = “xxx”)将其分解成更小的部分(如果存在,我愿意接受更好的解决方案)。
问题是我遇到了一个问题,我的一个脚本无法处理变量。示例代码如下:
build.gradle.kts
plugins { java }
repositories { mavenCentral() }
dependencies { testCompile("junit", "junit", "4.12") }
println("Before Apply")
apply(from = "./build.gradle.test.kts")
println("After Apply")
build.gradle.test.kts
println("Applying")
tasks.test {
val failedTests = mutableListOf<TestDescriptor>()
}
println("Applied")
这两个文件都位于根项目文件夹中。
输出。。。
>gradle clean build test
> Configure project :
Before Apply
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.kts' line: 6
* What went wrong:
Could not open cp_dsl generic class cache for script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts' (C:\Users\jamesdmcmillian\.gradle\caches\6.8\scripts\7kclhsg56vjpfm1z90j
4hwepn).
> Could not compile script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts'.
> startup failed:
script 'D:\Users\jamesdmcmillian\Projects\FacilitatorLabs\Labs\gradle-dsl-script-variables\build.gradle.test.kts': 4: expecting '}', found 'failedTests' @ line 4, column 9.
val failedTests = mutableListOf<TestDescriptor>()
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 4s
是否可以在应用的脚本中包含变量/值?
如果不是这样,这似乎是一个非常糟糕的限制。
这些帖子很接近,但没有回答变量问题:有没有办法拆分/分解 Gradle 构建的常见部分
另外,我已经阅读了 kotlin-dsl 入门,但没有看到任何特定于此问题的内容,或者我错过了它。代码的其余部分工作正常,因此我已将其从此问题中删除。
任何帮助都是值得赞赏的,提前致谢。
版本信息:
Gradle 6.8
Kotlin:1.4.20
Groovy:2.5.12
Ant:Apache Ant(TM) 版本 1.10.9 编译于 2020 年 9 月 27 日
JVM:11.0.2 (Oracle Corporation 11.0.2+9)
操作系统: Windows 10 10.0 amd64
答: 暂无答案
评论