2

我正在尝试使用 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
           }
        }
    }
}
4

1 回答 1

3

好的,所以继续阅读链接问题的答案,我已经实现了这个解决了我的问题。我最终的 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
            }
        }
    }
}
于 2017-05-15T12:46:21.297 回答