chenupt
chenupt

Reputation: 1781

Publish android library to nexus with gradle

I'm trying to publish my android library to nexus with gradle so that others people can use the code. But It does not work and return the error message:

> Could not publish configuration 'archives'

java.io.IOException: Could not PUT http://my-server/nexus/content/repositories/snapsho ts/TestLib/testlibdemo/unspecified/testlibdemo-unspecified.aar. Received status code 400 from server: Bad Request

Does the gradle supported that publishing the aar to Maven Central?

I'm a noob in gradle. Here is my build file.

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
}
}

apply plugin: 'maven'
apply plugin: 'android-library'


repositories {
mavenCentral()
flatDir name: "dist", dirs: "dist"
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

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

uploadArchives {
repositories {
    maven {
        credentials {
            username "admin"
            password "admin123"
        }
        url "http://myserver/nexus/content/repositories/snapshots"
    }
}
}

Upvotes: 1

Views: 1951

Answers (1)

Klunk
Klunk

Reputation: 825

I am not sure if this is relevant for Android but for plain old Java I needed to add the following to deploy to a Nexus repository using http.

configurations {
    deployJars
}

dependencies {
    deployJars "org.apache.maven.wagon:wagon-http:2.2"
}

I have this in the subprojects of my top level build.gradle for a multi-project build.

My uploadArchives also looks slightly different to yours with

uploadArchives {
    repositories.mavenDeployer {
        repository (url: "<repository url>") {
            authentication(userName: "<username>", password: "<password>")
        }
    }
}

I actually have the items in <> as properties in the gradle.properties file so I can override them on the command line, specifically the username and password. That way when I build from Team City I am not embedding my credentials into a file that colleagues can see. Team City allows me to store those values as build variables that are displayed as **.

Upvotes: 1

Related Questions