Reputation: 17627
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:
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?
Upvotes: 10
Views: 4459
Reputation: 1075
I upgraded Android Studio and therefore had also upgrade the ever-fragile unique snowflake that is gradle to version 8, i.e.
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
This upgrade broke my setup, here's my fix, where I upload the release aar to our internal maven repo server (could be archiva, could be nexus, etc.); to upload you'd need to run the 'publishCrazyClownBehaviourPublicationToMavenRepository' task.
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
}
android {
namespace = "die.gradle.die.please.lib"
compileSdk 33
defaultConfig {
minSdkVersion 15
targetSdkVersion 33
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
// this is important, scopes the build to the 'release' target/artifact
publishing {
singleVariant("release")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
afterEvaluate {
publishing {
publications {
repositories.maven {
url "https://your.maven.repo/goes/here/"
credentials {
username "crazy"
password "clown"
}
}
crazyClownBehaviour(MavenPublication) {
from components.release {
artifacts {
groupId 'die.gradle.die.please.lib'
artifactId 'die_gradle_die_please_lib'
version '6.6.6'
artifact 'build/outputs/aar/app-release.aar'
}
}
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
}
Greetz to the Gradle clown community, please lookup: backwards compatibility, tight coupling and colourful hats!
Upvotes: 0
Reputation: 17627
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'
}
}
}
}
Upvotes: 13