4
votes

I want to deploy my java library artifact on Artifactory But I am getting the following error. Failed to deploy file: HTTP response code: 401. HTTP response message: Unauthorized.

I followed the guide gradle artifactory plugin

Below is my build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
    mavenCentral()
 }

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile group: "com.squareup.retrofit", name: "retrofit", version: "1.7.0"
    compile group: "com.squareup.okhttp", name: "okhttp", version: "2.0.0"
    compile group: "com.squareup.okhttp", name: "okhttp-urlconnection", version: "2.0.0"

}
version = '1.0.0-SNAPSHOT'

group = 'com.xyz'

buildscript {
    repositories {
        maven {
            url 'http://localhost:8081/artifactory/libs-release'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
            name = "maven-main-cache"
        }

    }
    dependencies {
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
    }
}
apply plugin: 'maven-publish'
repositories {
    add buildscript.repositories.getByName("maven-main-cache")
}
allprojects {
    apply plugin: 'com.jfrog.artifactory'
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'libs-snapshot-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
        defaults {
            publications ('mavenJava')
        }
    }

}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

Can anyone guide me where am I going wrong?

1
Do you have the opportunity to check logs on artifactory, since that will give you a better idea why it's failingroomsg
Hmm, you're trying to publish a snaphsot artifact ("x.y.z-SNAPSHOT") into a release repository. By default, artifactory does not allow this. I guess logs on artifactory will tell you the same.roomsg
or you are allowed to publish it but don't have (delete) permissions to overwrite a previous deploy. And I guess there are other explanations as well...roomsg
No I am not trying to publish snapshot artifact into release repository. you can see in publish closure repoKey=libs-snapshot-local. I do have permission for deploy.Ashwin N Bhanushali
I am admin and I have all permissions.Ashwin N Bhanushali

1 Answers

0
votes

It can be happened when ~/.m2/settings.xml or $GRADLE_USER_HOME/gradle.properties are corrupted. Explicitly when you use encrypted password for Artifactory access. Try to regenerated it again.