我正在尝试使用 gradle's maven-publish
plugin导出在 Kotlin 中开发的 Android 库模块。aar 文件已成功生成并导出,但没有添加任何依赖项 - 根本没有,甚至 Kotlin 也没有。以下是基于此答案的插件配置:
apply plugin: 'maven-publish'
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
ext {
releaseRepository = "s3://****/maven/releases"
snapshotsRepository = "s3://****/maven/snapshots"
artifactRepository = "$buildDir/outputs/aar/render-engine-release.aar"
_version = properties.getProperty('lib.version')
_artifact = properties.getProperty('lib.name')
_group = properties.getProperty('lib.group')
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "source"
}
publishing {
publications {
maven(MavenPublication) {
groupId _group
artifactId _artifact
version _version
artifact (sourceJar)
artifact artifactRepository
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each {
if(_group != null && (_artifact != null || "unspecified" == _artifact) && _version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', _group)
dependencyNode.appendNode('artifactId', _artifact)
dependencyNode.appendNode('version', _version)
}
}
}
}
}
repositories {
maven {
if(_version.endsWith('-SNAPSHOT')) {
url snapshotsRepository
} else {
url releaseRepository
}
credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
}