我在此插件上使用了Gradle 6.2.2
:com.gorylenko.gradle-git-properties
(2.2.2
版本)。我正在尝试将以下代码段“翻译”为Kotlin DSL:
gitProperties {
extProperty = "gitProps" // git properties will be put in a map at project.ext.gitProps
}
shadowJar {
manifest {
attributes(
"Build-Revision": "${ -> project.ext.gitProps["git.commit.id"]}" // Uses GString lazy evaluation to delay until git properties are populated
)
}
}
...但这是我到目前为止提出的:
gitProperties {
extProperty = "gitProps"
keys = listOf("git.branch", "git.build.host", "git.build.version", "git.commit.id", "git.commit.id.abbrev",
"git.commit.time", "git.remote.origin.url", "git.tags", "git.total.commit.count")
}
tasks {
withType<ShadowJar> {
manifest.attributes.apply {
put("Build-Revision", "${project.ext.properties["git.commit.id"]}")
}
}
}
我无法弄清楚在Kotlin DSL中是否可以使“GString惰性评估”部分正常工作,也不知道
gitProps
映射如何适合于此。最终,这种方法(我知道这是部分错误的)返回了null
。有任何想法吗?
最佳答案
下面的Kotlin语法对我有用:
put("Build-Revision", object {
override fun toString():String = (project.extra["gitProps"] as Map<String, String>)["git.commit.id"]!!
})
关于gradle - 使用gradle-git-properties插件在Kotlin DSL中进行GString惰性评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60743468/