上传aar到maven

时间:2016-03-30 12:15:47

标签: java maven gradle

我正在将一些源集成功发布到maven存储库,但我确实需要公开我的.aar库。

我正在使用此tutorial

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.sourceFiles
}

根据我的理解,这个代码将它发送到存储库我的soucrse集,但是当我尝试发送我的aar时,它表示使用此代码对.aar的死记硬背不正确:

from android.lib.build.outputs.sourceFiles

那么如何发送位于\project\lib\build\outputs\aar\my_aar.aar的文件?

编辑:正如lase所说,这与凭证连接到maven但是没有部署aar:

mavenDeployer {
            def credentials = [
                    userName: NEXUS_USERNAME,
                    password: NEXUS_PASSWORD
            ]
            repository(url: "test",authentication:credentials)
            pom.artifactId = 'com.liv'
            pom.version = '1.5.0'
            pom.packaging = 'aar'
            pom.groupId = 'test2'
        }

并且幸运的是,如果没有此代码,此代码不会上传到maven存储库:

afterEvaluate { project ->


    signing {
        required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }


    task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.sourceFiles

    }

    artifacts {
        archives androidSourcesJar
    }
}
编辑:也许这个项目有特定的SourceSets所以我会发布它:

sourceSets {
    main {
        java.srcDirs = ['src/main/java']
        res.srcDirs = ['src/main/res']
        assets.srcDirs = ['assets']
    }

    liv {
        java.srcDirs = ['src/live/java']
        res.srcDirs = ['src/live/res']
        assets.srcDirs = ['src/main/assets']
        manifest.srcFile 'src/live/AndroidManifest.xml'
        jni.srcDirs = []
        jniLibs.srcDir 'src/main/libs'
    }

    live {
        java.srcDirs = ['src/live/java']
        res.srcDirs = ['src/live/res']
        assets.srcDirs = ['src/main/assets']
        manifest.srcFile 'src/live/AndroidManifest.xml'
    }
}

1 个答案:

答案 0 :(得分:1)

我正在使用这种策略。我应用的插件是com.android.librarymaven

android {
    ...
    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "http://mycompany/local/repositories/releases/")
                pom.artifactId = 'projectName'
                pom.version = '1.0.0'
                pom.packaging = 'aar'
                pom.groupId = 'com.mycompany'
            }
        }
}