Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle fails to download artifacts from Nexus maven repository - 401 Authorization required

Tags:

maven

gradle

I've configured gradle build to use our company's nexus repo but maven does not seem to be able to authorized correctly - I keep getting erros such as

Failed to get resource: HEAD. [HTTP HTTP/1.1 401 Authorization Required:    https://maven.gooddata.com/nexus/content/repositories/gooddata/org/codehaus/groovy/groovy-all/2.0.4/groovy-all-2.0.4.pom]

Strangely enough, the deploying to the same nexus repo (via mavenDeployer) is working seamlessly.

Below is part of my build script related to the maven repo configuration (maven_user and maven_password are defined in ~/.gradle/gradle.properties).

apply plugin: 'maven'

ext {
    repos = [
            my : "<my_repo_url>",
            my_snapshot : "<my_snapshots_repo_url>"
    ]

}


repositories {
    mavenLocal()

    maven {
        url repos.my
        credentials {
            username = maven_user
            password = maven_password
        }
    }
    maven {
        url repos.my_snapshot
        credentials {
            userName = maven_user
            password = maven_password
        }
    }

    mavenCentral()
    maven { url "http://repository.codehaus.org/" }
    maven { url "http://sardine.googlecode.com/svn/maven" }
    maven { url "http://snapshots.repository.codehaus.org" }

}


uploadArchives {
    repositories.mavenDeployer {
        repository(url : repos.my) {
            authentication(userName : maven_user, password : maven_password)
        }
        snapshotRepository(url : repos.my_snapshot) {
            authentication(userName : maven_user, password : maven_password)
        }
    }
}

Any suggestions what's going on?

like image 517
Juraj Martinka Avatar asked Dec 19 '12 11:12

Juraj Martinka


People also ask

Could not head received status code 401 from server unauthorized?

The 401 Unauthorized Error is an HTTP status code error that represented the request sent by the client to the server that lacks valid authentication credentials. It may be represented as 401 Unauthorized, Authorization required, HTTP error 401- Unauthorized. It represents that the request could not be authenticated.

What is Nexus repository?

Nexus Repository OSS is an open source repository that supports many artifact formats, including Docker, Java™, and npm. With the Nexus tool integration, pipelines in your toolchain can publish and retrieve versioned apps and their dependencies by using central repositories that are accessible from other environments.


2 Answers

Your username property is capitalized wrongly and you should leave out the '=' sign with the username and password setting. Changing your repository definition to the following should solve your problems:

maven {
    url repos.my
    credentials {
        username maven_user
        password maven_password
    }
}
like image 173
Hiery Nomus Avatar answered Oct 16 '22 10:10

Hiery Nomus


Thread is a bit old now, but just wanted to highlight a gotcha I had when following the above .. my admin had created a password with both a single and double quote in, which resulted in a similar 401

like image 44
user1102665 Avatar answered Oct 16 '22 11:10

user1102665