Codearte / gradle-nexus-staging-plugin

Automatize releasing Gradle projects to Maven Central.
Apache License 2.0
172 stars 26 forks source link

Please make sure that closeAndReleaseRepository task works #131

Closed denis-zhdanov closed 3 years ago

denis-zhdanov commented 4 years ago

Problem

closeAndReleaseRepository task fails all the time:

./gradlew closeAndReleaseRepository

> Task :closeRepository FAILED
GET request failed. 401: Unauthorized, body: <empty>

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':closeRepository'.
> 401: Unauthorized, body: <empty>

It used to work before, failed after all versions were updated (plugin version is 0.21.1; gradle version is 5.6.2)

szpak commented 4 years ago

Hmm, I don't want to sound like a heldesk guy, but "it works on my machine" (to be precise on my CI server :) ). Today, 3 days ago and earlier.

During the aforementioned build there are 2 dummy (but real) Gradle projects released to Sonatype Nexus. They are occasional timeouts, but definitely not "401: Unauthorized".

Have you tried to downgrade to the previous version of GNSP that was working for you? Maybe it's just problem with your credentials (especially Nexus access token)?

szpak commented 4 years ago

Ping @denis-zhdanov.

slonopotamus commented 4 years ago

I've successfully made a release using Gradle 5.6.1 + nexus-staging-plugin 0.21.1 + nexus-publish 0.3.1 (warning, there's verbose output turned on because I was diagnosing issues with Sonatype OSS Nexus, unrelated to Gradle plugins). Here's build.gradle that was used for that release.

szpak commented 4 years ago

Great that it worked in the end. What was the reason of initial 401 failure?

slonopotamus commented 4 years ago

No. I am not @denis-zhdanov. I just added my comment to confirm that GNSP works for someone who is not a GNSP author :)

szpak commented 4 years ago

Ups, sorry, the original comment was not visible at the time I was writing mine :).

denis-zhdanov commented 4 years ago

I tried downgrading to the previous version and it failed for me as well.

Also oss nexus web dashboard looks extremely slow when I try to close/release manually - operations take a while and often result in 503

szpak commented 4 years ago

@denis-zhdanov 503 is a known issue on the Sonatype side. 401 rather not. I still suspect there is something wrong with the credentials. Can you send me link to the project build.gradle and a CI build? If not, please paste the configuration part related to publishing (maven/maven-publish, GNSP, GNP, etc.)

akashraje commented 4 years ago

I'm facing the same problem. I provide nexus credentials through nexusUsername and nexusPassword in global gradle.properties. I see same results when I execute getStagingProfile.

> Task :closeRepository FAILED
Task ':closeRepository' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Getting staging profile for package group 'com.dummy'
GET request failed. 401: Unauthorized, body: <empty>
:closeRepository (Thread[Execution worker for ':',5,main]) completed. Took 1.764 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':closeRepository'.
> 401: Unauthorized, body: <empty>

My build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.1"
    }
}

plugins {
    id 'java'
    id 'maven'
    id 'io.codearte.nexus-staging' version '0.21.1'
}

uploadArchives {
    def nexusUser = "${nexusUsername}"
    def nexusPassword = "${nexusPassword}"

    repositories {
        mavenDeployer {
            repository(url: 'http://localhost:8081/repository/maven-releases/') {
                authentication(userName: nexusUser, password: nexusPassword);
            }
            snapshotRepository(url: 'http://localhost:8081/repository/maven-snapshots/') {
                authentication(userName: nexusUser, password: nexusPassword);
            }
            pom.artifactId = 'log-configurer'
        }
    }
}

Does this work only with Nexus Repository Manager Pro ?

szpak commented 4 years ago

@akashraje

GET request failed. 401: Unauthorized, body:

suggests the problem with your credentials. However, you set it in the mavenDeployer section and in addition you seem to have the nexusUsername and nexusPassword variables set.

Nevertheless, only credentials are taken from the mavenDeployer settings. Please try to set servelUrl to do not hit Sonatype Nexus:

nexusStaging {
    serverUrl = "http://localhost:8081/...."
}

where "..." in the URL represents the root path where API is available - for sonatype it is https://oss.sonatype.org/service/local/, but for local installation it's probably something else.

Btw, just to be sure. You use Nexus 2.x, right?

akashraje commented 4 years ago

@szpak

I was using Nexus 3.20.1.

I installed Nexus 2.14.16 today and tried. With Nexus 3 and Nexus 2 both I am able to deploy snapshots successfully to Snapshots repository.

However, with Nexus 2 I see the same issue.

> Task :closeRepository FAILED
GET request failed. 401: Unauthorized, body: <empty>

I tried adding credentials specifically

nexusStaging {
        username = "${nexusUsername}"
        password = "${nexusPassword}"
}

Regarding the serverUrl. I looked around a bit and this URL worked for other APIs http://localhost:8081/nexus/service/local/. It worked for status users with xml output.

After adding this in nexusStaging I get 404 with HTML parsing error.

szpak commented 3 years ago

TL;TD. Please check gradle-nexus-publish-plugin and report a separate issue there is the problem still occurs.

A longer version. To make releasing to Maven Central even easier, I and Marc Phillip (the author of nexus-publish-plugin) combined forces to create a next generation, unified, 2-in-1 plugin - gradle-nexus-publish-plugin. It is a recommended solution, as our development effort will be put in that new plugin. See my blog post and the official migration guide.