10

I´m trying to publish the generated aar file of my android library to my Apache Archiva Maven server, but I haven´t manage to get it working yet because either the examples are outdated or they are for java and not for android

After noticing that most methods of the gradle examples are deprecated, I found this new documentation:

Gradle Documentation

Which describes how to use the new API which seems to replace uploadArchives with publishing and so on....

So this is what I´ve got so far:

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"


defaultConfig {
    applicationId "com.mycompany.mylibrary"
    minSdkVersion 9
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    abortOnError false
}

}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.android.support:appcompat-v7:21.0.3'
}

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

publishing {

publications {
    mavenJava(MavenPublication) {
        groupId 'com.android.mylibrary'
        artifactId 'MyLibrary'
        version '1.0.0'

        from components.java

        artifact sourceJar {
            classifier "sources"
        }
    }
}
repositories {
    maven {
        url "myurl"
        credentials{
            username "user"
            password "password"
        }
    }
}
}

The Gradle stuff is like the hell for me. I don´t know what is right and what is wrong and some things seem to be changed without any hints that it isn´t supported anymore, which makes it quite difficult to solve these problems...

How can I automatically upload the generated aar file to my Apache Archiva?

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136

1 Answers1

13

Solved it by myself

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"


repositories {
    mavenCentral()
}

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


dependencies {
   compile fileTree(include: ['*.jar'], dir: 'libs')
   provided 'com.android.support:support-v4:21.0.3'
   provided 'com.android.support:appcompat-v7:21.0.3'
}

task sourceJar(type: Jar) {
   classifier "source"
}

publishing {
   publications {

       repositories.maven {
           url 'myurl/repositories/myrepo'
           credentials {
               username "user"
               password "password"
           }
       }

       maven(MavenPublication) {
           artifacts {
               groupId 'com.mycompany'
               artifactId 'mylibrary'
               version '1.0'
               artifact 'build/outputs/aar/app-release.aar'
           }
       }
   }

}
Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
  • 1
    What a simple and effective solution. Worked like charm :) – Nitin Bansal Aug 13 '15 at 09:20
  • 3
    But this won't build proper pom.xml file, you will miss depndency data and that useless – outlying Jan 21 '16 at 11:13
  • It has nothing to do with the build process, it just uploads the aar to your server. You might have another problem elsewhere – Marian Klühspies Jan 21 '16 at 11:20
  • Answer does **NOT WORK** properly. Basically as pointed out by outlying you won't get a auto generated pom.xml from this approach which will render the resulting aar useless. –  Oct 04 '16 at 14:55
  • I was using this in production for over two years now. I don´t see any problem related to a missing pom.xml. Why do you need that? @uniqueentity – Marian Klühspies Apr 21 '17 at 09:31