9

我尝试将库发布到私有 S3 Maven 存储库。上传受密码保护,但下载库对公众开放。aar 文件上传没有问题(连同 pom/md5/sha1),我可以在我的 S3 存储桶中看到它,下载它,甚至手动将此 aar 作为依赖项添加到我的项目中。但是,当我像这样加载此依赖项时:

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "http://myrepo.com" }
}

//in the project's build.gradle
implementation 'com.mylib:mylib:0.1.1'

……有问题。Gradle 同步完成没有问题,看起来 aar 已经下载,但它从未出现在 Android Studio 的“外部库”部分中,并且代码不可用(Unresolved reference: MyLib)。

当然,我尝试重建、使缓存无效并将其应用于不同的项目。

任何想法如何使它工作?

这就是 maven-publish 代码的样子。

android.libraryVariants.all { variant ->

    if (variant.buildType.name == "release" && variant.flavorName == "prod") {

        variant.outputs.all { output ->

            publishing.publications.create(variant.name, MavenPublication) {

                artifact source: output.outputFile, classifier: output.name

                pom.withXml {
                    def dependencies = asNode().appendNode('dependencies')

                    configurations.getByName(variant.name + "CompileClasspath").allDependencies
                            .findAll { it instanceof ExternalDependency }
                            .each {
                        def dependency = dependencies.appendNode('dependency')

                        dependency.appendNode('groupId', it.group)
                        dependency.appendNode('artifactId', it.name)
                        dependency.appendNode('version', it.version)

                    }
                }
            }
        }

    }
}

tasks.all { task ->
    if (task instanceof AbstractPublishToMaven) {
        task.dependsOn assemble
    }
}

publishing {

    Properties properties = new Properties()
    properties.load(file('maven.properties').newDataInputStream())

    def user = properties.getProperty("maven.user")
    def password = properties.getProperty("maven.password")

    repositories {
        maven {
            url "s3://myrepo.com/"
            credentials(AwsCredentials) {
                accessKey user
                secretKey password
            }
        }
    }
}
4

1 回答 1

5

显然,当涉及到风味时,那些部署插件(包括这个插件和 bintray 插件)都会遇到一些重大困难。我不知道具体情况,但这与他们试图根据文件名解析工件名称有关。这一行:

artifact source: output.outputFile, classifier: output.name

这就是我的工件被命名为 eg 的原因com/mylib/mylib/0.1.1/mylib-0.1.1-prod-release.aar。从maven加载依赖项时不知何故无法识别。将此行更改为:

artifact source: output.outputFile, classifier: null

使文件看起来像这样com/mylib/mylib/0.1.1/mylib-0.1.1.aar,这显然很好。

我不知道为什么第一种命名方式不起作用,我假设有一个设置可以将它传播到元数据。这个问题仍然有赏金所以也许有人可以解决这个谜团?

于 2018-06-15T13:32:01.777 回答