Kotlin Android库模块导出与gradle maven-publish插件不添加依赖关系

我正尝试使用gradle的maven-publish 插件导出在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 } } } } 

One Solution collect form web for “Kotlin Android库模块导出与gradle maven-publish插件不添加依赖关系”

好吧,所以不断阅读关于链接问题的答案,我已经实现了这个解决了我的问题。 我的最终publish.gradle是这样的:

 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.getAllDependencies().each { Dependency dep -> if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") return def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', dep.group) dependencyNode.appendNode('artifactId', dep.name) dependencyNode.appendNode('version', dep.version) if (!dep.transitive) { def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') exclusionNode.appendNode('groupId', '*') exclusionNode.appendNode('artifactId', '*') } else if (!dep.properties.excludeRules.empty) { def exclusionsNode = dependencyNode.appendNode('exclusions') dep.properties.excludeRules.each { ExcludeRule rule -> def exclusionNode = exclusionsNode.appendNode('exclusion') exclusionNode.appendNode('groupId', rule.group ?: '*') exclusionNode.appendNode('artifactId', rule.module ?: '*') } } } } } } repositories { maven { if (_version.endsWith('-SNAPSHOT')) { url snapshotsRepository } else { url releaseRepository } credentials(AwsCredentials) { accessKey AWS_ACCESS_KEY secretKey AWS_SECRET_KEY } } } } 
Kotlin language will be the best programming language for Android.