我在我的 Android 库的 Groovy DSL build.gradle
文件中使用 maven-publish 和
signingGradle 插件,如下所示:
plugins {
id("maven-publish")
id("signing")
}
android {
publishing {
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}
publishing {
publications {
release(MavenPublication) {
afterEvaluate {
from components.release
}
groupId getProperty("groupId")
artifactId getProperty("artifactId")
version getProperty("version")
}
}
repositories {
maven {
url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username getProperty("sonatypeUsername")
password getProperty("sonatypePassword")
}
}
}
}
signing {
sign publishing.publications.release
}
我省略了
build.gradle
文件中与发布和签名无关或可选的部分。
如何将这些声明转换为 Kotlin DSL?
以下是转换为 Kotlin DSL 的声明:
plugins {
`maven-publish`
signing
}
android {
publishing {
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}
publishing {
publications {
create<MavenPublication>("release") {
afterEvaluate {
from(components["release"])
}
groupId = project.properties["groupId"].toString()
artifactId = project.properties["artifactId"].toString()
version = project.properties["version"].toString()
}
}
repositories {
maven {
name = "sonatype"
credentials(PasswordCredentials::class)
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2//artifactory/libs-release")
}
}
}
signing {
sign(publishing.publications["release"])
}
此处找到完整的
build.gradle.kts
文件,其中包含上述所有声明。credentials(credentialsType:)
函数在声明存储库>处理凭证Gradle文档中进行了描述。