Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish aar file to Apache Archiva with Gradle

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?

like image 805
Marian Klühspies Avatar asked Dec 28 '14 13:12

Marian Klühspies


1 Answers

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

}
like image 85
Marian Klühspies Avatar answered Nov 16 '22 02:11

Marian Klühspies