2

When I run ./gradlew uploadArchives to deploy my library artifact to Artifactory server, I get the following error:

Uploading: com/example/android-lib/1.0.0-SNAPSHOT/android-lib-1.0.0-20150311.112243-1.aar to repository remote at http://artifactory:8081/artifactory/libs-snapshot-local
 Transferring 3787K from remote
Error writing to server
android-lib:uploadArchives FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':android-lib:uploadArchives'.
> Could not publish configuration 'archives'
> Error deploying artifact 'com.example:android-lib:aar': Error deploying artifact: Error transferring file

On the server, according to my understanding from the log, we receive error 401. Here's the log:

20150311144749|2|REQUEST|192.168.148.66|myuser|PUT|
/libs-snapshot-local/com/example/android-lib/1.0.0-SNAPSHOT/android-lib-1.0.0-20150311.112243-1.aar|HTTP/1.1|401|3878210

I have the following build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.+'
        classpath 'com.github.dcendents:android-maven-plugin:1.2'
    }
}

repositories {
    jcenter()
}

apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'com.github.dcendents.android-maven'

version = "1.0.0-SNAPSHOT"
group = "com.example"

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 21
        versionCode 1
        versionName version
    }

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

dependencies {
    compile 'com.android.support:support-v4:21.0.2'
}



uploadArchives {
    configuration = configurations.archives

    repositories {
        mavenDeployer {
            repository(url: 'http://artifactory:8081/artifactory/libs-snapshot-local') {
                authentication(userName: artifactoryUsername, artifactoryPassword)
            }

            pom.project {
                name 'android-lib'
                description 'cool lib'

                scm {
                    developerConnection '<repo url>'
                }
            }
        }
    }
}
Nimrod Dayan
  • 3,050
  • 4
  • 29
  • 45
  • 1
    Check that the "Maven Snapshot Version Behavior" of the target repository is not set to Nonunique – Dror Bereznitsky Mar 10 '15 at 15:58
  • "Maven Snapshot Version Behavior" is currently set to "Unique" for all of our repositories. I'm not sure if the problem is with the built archive by the `Gradle Artifactory plugin` or on `Artifactory` server. At least regular Java Jar artifacts published with Maven seem to be built with timestamp already during build time so when the archive is uploaded to Artifactory it already has the filenames with timestamps. What we'd like to have is the same behavior as Maven publish. – Nimrod Dayan Mar 11 '15 at 11:02
  • OK we decided to completely drop the Gradle Artifactory plugin and use only Maven plugin. I can see the artifact is generated properly in my local ~/.m2/repository but for some odd reason, Artifactory rejects it. I'll update the question to reflect what we are trying to achieve. – Nimrod Dayan Mar 11 '15 at 13:03

1 Answers1

1

The authentication part seems to be broken - password is not passed correctly.
It should be:

repository(url: 'http://artifactory:8081/artifactory/libs-snapshot-local') {
    authentication(userName: artifactoryUsername, password: artifactoryPassword)
}
Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57