Nxrm3-maven-plugin + Nexus3 = 401 Not Authorized for user, 404 on tags API for admin

I’m attempting to push my artifacts to Nexus (3.18.0-01, docker) from a GitLab Runner, but I’m getting the following error:

Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Get tag was unsuccessful (401 response from server): Unauthorized -> [Help 1]

I followed GitLab guide, which works, and changed the relevant portions to Nexus.
https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/

Here are my maven details using the Sonatype guide (Repository Manager for Maven Plugin):

Tag properties:

<properties>
    <nxrm3.staging.tag>${project.artifactId}-${project.version}</nxrm3.staging.tag>
</properties>

Distribution element:

<distributionManagement>
    <repository>
        <id>my-nexus</id>
        <name>my-nexus</name>
        <url>${env.MAVEN_REPO_URL}/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
        <id>my-nexus</id>
        <name>my-nexus</name>
        <url>${env.MAVEN_REPO_URL}/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>

Plugin configuration:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8.2</version>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nxrm3-maven-plugin</artifactId>
        <version>1.0.2</version>
        <extensions>true</extensions>
        <executions>
            <execution>
                <id>default-deploy</id>
                <phase>deploy</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
        </executions>
    <configuration>
        <serverId>my-nexus</serverId>
        <nexusUrl>${env.MAVEN_REPO_URL}</nexusUrl>
        <repository>maven-releases</repository>
        <tag>${nxrm3.staging.tag}</tag>
    </configuration>
</plugin>

[project_folder]/.m2/settings.xml:

<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
    xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <servers>
        <server>
          <id>my-nexus</id>
          <username>${env.MAVEN_REPO_USER}</username>
          <password>${env.MAVEN_REPO_PASS}</password>
        </server>
      </servers>
    </settings>

MAVEN_REPO_URL, MAVEN_REPO_USER and MAVEN_REPO_PASS are set in GitLab. The user was added to the admin role to eliminate that as the authorization problem, but that didn’t work. Nexus is running in a docker container and exposed on port 8081, so it’s URL is set to http://myipaddress:8081.

For completeness, here is my .gitlab-ci.yml:

image: maven:3-jdk-8

variables:
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

cache:
  paths:
    - .m2/repository/
    - target/

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS compile
  tags:
    - maven
    
test:
  stage: test
  script:
    - mvn $MAVEN_CLI_OPTS test
  tags:
    - maven

deploy:
  stage: deploy
  script:
    - mvn $MAVEN_CLI_OPTS deploy
  tags:
    - maven
  only:
    - master

I checked the Log Viewer and there is nothing in there. Below is the entire post build/test output:

[INFO] 
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ my-project ---
[INFO] Building jar: /builds/util/my-project/target/my-project-1.0.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-project ---
[INFO] Installing /builds/util/my-project/target/my-project-1.0.0.jar to /builds/util/my-project/.m2/repository/com/myis/license/my-project/1.0.0/my-project-1.0.0.jar
[INFO] Installing /builds/util/my-project/pom.xml to /builds/util/my-project/.m2/repository/com/myis/license/my-project/1.0.0/my-project-1.0.0.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ my-project ---
[INFO] Skipping artifact deployment
[INFO] 
[INFO] --- nxrm3-maven-plugin:1.0.2:deploy (default-deploy) @ my-project ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.264 s
[INFO] Finished at: 2019-08-06T19:50:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Get tag was unsuccessful (401 response from server): Unauthorized -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

And the full debugging info. I did BASE64 decode the Basic auth string, and it did have my username:password correctly set:

[INFO] --- nxrm3-maven-plugin:1.0.2:deploy (default-deploy) @ my-project ---
[DEBUG] Configuring mojo org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy from plugin realm ClassRealm[extension>org.sonatype.plugins:nxrm3-maven-plugin:1.0.2, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[DEBUG] Configuring mojo 'org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy' with basic configurator -->
[DEBUG]   (f) artifact = com.agois.license:my-project:jar:1.0.0
[DEBUG]   (f) attachedArtifacts = []
[DEBUG]   (f) mavenSession = org.apache.maven.execution.MavenSession@426e505c
[DEBUG]   (f) nexusUrl = http://myipaddress:8081
[DEBUG]   (f) offline = false
[DEBUG]   (f) packaging = jar
[DEBUG]   (f) pluginArtifactId = nxrm3-maven-plugin
[DEBUG]   (f) pluginGroupId = org.sonatype.plugins
[DEBUG]   (f) pomFile = /builds/util/my-project/pom.xml
[DEBUG]   (f) repository = maven-releases
[DEBUG]   (f) serverId = ago-nexus
[DEBUG]   (f) tag = my-project-1.0.0
[DEBUG] -- end configuration --
[DEBUG] CookieSpec selected: default
[DEBUG] Re-using cached 'basic' auth scheme for http://myipaddress:8081
[DEBUG] Connection request: [route: {}->http://myipaddress:8081][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[DEBUG] Connection leased: [id: 0][route: {}->http://myipaddress:8081][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] Opening connection {}->http://myipaddress:8081
[DEBUG] Connecting to /myipaddress:8081
[DEBUG] Connection established 172.17.0.4:45720<->myipaddress:8081
[DEBUG] Executing request GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1
[DEBUG] Target auth state: CHALLENGED
[DEBUG] Proxy auth state: UNCHALLENGED
[DEBUG] http-outgoing-0 >> GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1
[DEBUG] http-outgoing-0 >> Host: myipaddress:8081
[DEBUG] http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)
[DEBUG] http-outgoing-0 >> Accept-Encoding: gzip,deflate
[DEBUG] http-outgoing-0 >> Authorization: Basic REMOVED
[DEBUG] http-outgoing-0 >> "GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1[\r][\n]"
[DEBUG] http-outgoing-0 >> "Host: myipaddress:8081[\r][\n]"
[DEBUG] http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)[\r][\n]"
[DEBUG] http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[DEBUG] http-outgoing-0 >> "Authorization: Basic REMOVED[\r][\n]"
[DEBUG] http-outgoing-0 >> "[\r][\n]"
[DEBUG] http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
[DEBUG] http-outgoing-0 << "Date: Tue, 06 Aug 2019 20:35:00 GMT[\r][\n]"
[DEBUG] http-outgoing-0 << "Server: Nexus/3.18.0-01 (OSS)[\r][\n]"
[DEBUG] http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
[DEBUG] http-outgoing-0 << "WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"[\r][\n]"
[DEBUG] http-outgoing-0 << "Content-Length: 0[\r][\n]"
[DEBUG] http-outgoing-0 << "[\r][\n]"
[DEBUG] http-outgoing-0 << HTTP/1.1 401 Unauthorized
[DEBUG] http-outgoing-0 << Date: Tue, 06 Aug 2019 20:35:00 GMT
[DEBUG] http-outgoing-0 << Server: Nexus/3.18.0-01 (OSS)
[DEBUG] http-outgoing-0 << X-Content-Type-Options: nosniff
[DEBUG] http-outgoing-0 << WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"
[DEBUG] http-outgoing-0 << Content-Length: 0
[DEBUG] Connection can be kept alive indefinitely
[DEBUG] Authentication required
[DEBUG] myipaddress:8081 requested authentication
[DEBUG] Authorization challenge processed
[DEBUG] Authentication failed
[DEBUG] Clearing cached auth scheme for http://myipaddress:8081
[DEBUG] Connection [id: 0][route: {}->http://myipaddress:8081] can be kept alive indefinitely
[DEBUG] Connection released: [id: 0][route: {}->http://myipaddress:8081][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]

In an attempt to further debug, I changed to using the admin user. Not the error changed to 404 as it couldn’t find the tags path.

[DEBUG] http-outgoing-0 >> POST /service/rest/v1/tags? HTTP/1.1
[DEBUG] http-outgoing-0 >> Content-Length: 44
[DEBUG] http-outgoing-0 >> Content-Type: application/json; charset=UTF-8
[DEBUG] http-outgoing-0 >> Host: myipaddress:8081
[DEBUG] http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)
[DEBUG] http-outgoing-0 >> Accept-Encoding: gzip,deflate
[DEBUG] http-outgoing-0 >> Authorization: Basic REMOVED=
[DEBUG] http-outgoing-0 >> "POST /service/rest/v1/tags? HTTP/1.1[\r][\n]"
[DEBUG] http-outgoing-0 >> "Content-Length: 44[\r][\n]"
[DEBUG] http-outgoing-0 >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
[DEBUG] http-outgoing-0 >> "Host: myipaddress:8081[\r][\n]"
[DEBUG] http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)[\r][\n]"
[DEBUG] http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[DEBUG] http-outgoing-0 >> "Authorization: Basic REMOVED=[\r][\n]"
[DEBUG] http-outgoing-0 >> "[\r][\n]"
[DEBUG] http-outgoing-0 >> "{"name":"my-project-1.0.0","attributes":{}}"
[DEBUG] http-outgoing-0 << "HTTP/1.1 404 Not Found[\r][\n]"
[DEBUG] http-outgoing-0 << "Date: Tue, 06 Aug 2019 21:01:11 GMT[\r][\n]"
[DEBUG] http-outgoing-0 << "Server: Nexus/3.18.0-01 (OSS)[\r][\n]"
[DEBUG] http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
[DEBUG] http-outgoing-0 << "X-Siesta-FaultId: 667d300f-d3d6-41f2-8786-11f502a19910[\r][\n]"
[DEBUG] http-outgoing-0 << "Content-Length: 0[\r][\n]"
[DEBUG] http-outgoing-0 << "[\r][\n]"
[DEBUG] http-outgoing-0 << HTTP/1.1 404 Not Found
[DEBUG] http-outgoing-0 << Date: Tue, 06 Aug 2019 21:01:11 GMT
[DEBUG] http-outgoing-0 << Server: Nexus/3.18.0-01 (OSS)
[DEBUG] http-outgoing-0 << X-Content-Type-Options: nosniff
[DEBUG] http-outgoing-0 << X-Siesta-FaultId: 667d300f-d3d6-41f2-8786-11f502a19910
[DEBUG] http-outgoing-0 << Content-Length: 0
[DEBUG] Connection can be kept alive indefinitely
[DEBUG] Connection [id: 0][route: {}->http://myipaddress:8081] can be kept alive indefinitely
[DEBUG] Connection released: [id: 0][route: {}->http://myipaddress:8081][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.472 s
[INFO] Finished at: 2019-08-06T21:01:11Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Create tag was unsuccessful (404 response from server): Not Found -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Create tag was unsuccessful (404 response from server)

After checking the API pages in my deployment, sure enough there is no tags path:

GET    /v1/assets
GET    /v1/assets/{id}
DELETE /v1/assets/{id}
GET    /v1/blobstores/{id}/quota-status
GET    /v1/components
POST   /v1/components
GET    /v1/components/{id}
DELETE /v1/components/{id}
GET    /v1/formats/{format}/upload-specs
GET    /v1/formats/upload-specs
PUT    /v1/lifecycle/bounce
GET    /v1/lifecycle/phase
PUT    /v1/lifecycle/phase
GET    /v1/read-only
POST   /v1/read-only/force-release
POST   /v1/read-only/freeze
POST   /v1/read-only/release
GET    /v1/repositories
GET    /beta/routing-rules
POST   /beta/routing-rules
GET    /beta/routing-rules/{name}
PUT    /beta/routing-rules/{name}
DELETE /beta/routing-rules/{name}
GET    /v1/script
POST   /v1/script
GET    /v1/script/{name}
PUT    /v1/script/{name}
DELETE /v1/script/{name}
POST   /v1/script/{name}/run
GET    /v1/search
GET    /v1/search/assets
GET    /v1/search/assets/download
GET    /beta/security/user-sources
GET    /beta/security/users
POST   /beta/security/users
PUT    /beta/security/users/{userId}
DELETE /beta/security/users/{userId}
PUT    /beta/security/users/{userId}/change-password
GET    /v1/status
GET    /v1/status/writable
POST   /v1/support/supportzip
GET    /v1/tasks
GET    /v1/tasks/{id}
POST   /v1/tasks/{id}/run
POST   /v1/tasks/{id}/stop

So, I guess the question is, is there a way to suppress the plugin from attempting to access the tags path? If not, is the tags API not available with the OSS version?

Hey John,

The Repository Manager for Maven Plugin you referenced and Tagging are both Repository Pro only features.

There is an automated free trial if you want try out your setup with Pro and see if it works how you expect.

Cheers,

Nick