【发布时间】:2020-07-24 10:24:51
【问题描述】:
我有一个 Gradle Kotlin DSL 脚本,可以将一些工件发布到本地 Maven 存储库:
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "my.company"
artifactId = project.name
version = "0.0.1"
from(components["java"])
}
}
repositories {
maven {
url = uri("https://maven.mycompany.com/content/repositories/whatever")
credentials {
username = (read from some file)
password = (read from some file)
}
}
}
}
如您所见,Gradle 将总是尝试从文件中读取用户名和密码。即使发布任务不会被执行。
我试图通过将凭据移动到发布任务中的 doFirst 块来修复它,但代码根本就不会执行:
publishing {
doFirst { // this doesn't compile, doFirst doesn't exist here
}
}
tasks.getByName("publish").doFirst {
// this compiles just fine, but it's never executed
}
tasks.named("publish") {
doFirst {
// this compiles just fine, but it's never executed
}
}
如何设置凭据以使其仅在执行发布任务时发生?
【问题讨论】:
标签: kotlin gradle maven-publish