4

I'm publishing some source sets successfully to maven repository but I really need to public my .aar library instead.

I'm using this tutorial

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

And with this code as I understand it sends to repository my soucrse sets but when I try to send my aar it says that the rote to .aar is not correct with this code:

from android.lib.build.outputs.sourceFiles

So how can I send my file located at \project\lib\build\outputs\aar\my_aar.aar ?

EDIT: as lase said this connects to maven with credentials BUT doesn't deploy 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'
        }

And unfurtunately this code doesn't upload anything without this to maven repository:

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
    }
}

EDIT: maybe this project has specific SourceSets so I would post it:

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'
    }
}
Kyryl Zotov
  • 1,788
  • 5
  • 24
  • 44
  • See this question: http://stackoverflow.com/q/35383243/4107809 – mattm Mar 30 '16 at 13:43
  • Kirill, are you sure that the `aar` is getting created at all, or are you only seeing the `jar` on your local? – lase Mar 30 '16 at 18:43
  • @lase Yes, it is created at \MyProject\lib\build\outputs\aar – Kyryl Zotov Mar 30 '16 at 18:52
  • I noticed the tutorial you posted doesn't have `apply plugin: 'com.android.library'`. That is all I am doing to generate my `aar` - no `jar` is generated using my scheme. i.e. `gradle build uploadArchives` – lase Mar 30 '16 at 18:58

1 Answers1

1

I'm doing exactly that using this strategy. My applied plugins are com.android.library and maven.

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'
            }
        }
}
lase
  • 2,508
  • 2
  • 24
  • 35
  • And how to add here authorization? Because my repository is private? – Kyryl Zotov Mar 30 '16 at 16:25
  • def credentials = [ userName: NEXUS_USERNAME, password: NEXUS_PASSWORD ] repository(url: "url",authentication:credentials) – Kyryl Zotov Mar 30 '16 at 16:38
  • Yes, I got my authentication but my aar is not uploading with just this piece of code. – Kyryl Zotov Mar 30 '16 at 16:45
  • I get there jar extension not aar as i wanted – Kyryl Zotov Mar 30 '16 at 17:48
  • The Maven Plugin reference is located [here](https://docs.gradle.org/current/userguide/maven_plugin.html) where you can read up on authentication. As for jar vs aar, that wouldn't really pertain to the upload portion, but rather to how it's built. – lase Mar 30 '16 at 18:10
  • 1
    Thanks, I already solve the authentication solutions, what do you mean "but rather to how it's built", could you please help here or advice where to look. I'm doing `gradlew uploadArchives --stacktrace` script – Kyryl Zotov Mar 30 '16 at 18:15