Kevin Milner
Kevin Milner

Reputation: 859

maven getting "Not Authorized" when trying to access nexus private repository

I've set up a private nexus repo manager on an EC2 instance and followed the various instructions floating around the internet on how to set up a maven project to use it. I have also disabled the anonymous account. I am able to connect and copy repositories via curl -U username:password <the_url> and it seems to work fine. However when I try to use maven (any goals) The very first thing I get is

    [WARNING] Could not transfer metadata org.apache.maven.plugins:maven-compiler-plugin/maven-metadata.xml from/to nexus (http://MY_NEXUS_HOST:8081/nexus/content/groups/public): Not authorized , ReasonPhrase:Unauthorized.

The mvn command then fails because it can't find the plugin anywhere. So the fact that I can use the rest command and it works as expected, but not through maven indicates to me that it is a problem with the configuration. I think I understand what's going on pretty well, and I've checked and rechecked the files, but I don't see anything wrong. Here's the settings.xml file

<servers>
  <server>
      <id>nexus-snapshot</id>
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>
  <server>
      <id>nexus-release</id>
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>

</servers>
<mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
              <enabled>true</enabled>
          </releases>
          <snapshots>
              <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases>
              <enabled>true</enabled>
              <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
              <enabled>true</enabled>
              <updatePolicy>always</updatePolicy>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

And here is the relevent portion of the pom file

    <distributionManagement>
        <repository>
            <id>nexus-release</id>
            <name>Nexus Release Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshot</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://MY_NEXUS_HOST:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

I'm wondering if there's a way to see the exact issue I'm running into. For instance, if I'm getting a 401, 403 or (for some reason?) 404. If someone can please help me I'd be ever so greatful. Oh, both maven and nexus are the latest versions as of last week. *edited because no matter how many times you check something before hitting submit...

Upvotes: 5

Views: 20071

Answers (1)

Kevin Milner
Kevin Milner

Reputation: 859

Oh my funky goat. The problem was that apparently in settings.xml, the Id field has to be the same as the one in the server field. ie:

<servers>
 <server>
      <id>nexus-release</id>          <---THIS MUST MATCH
      <username>USER_NAME</username>
      <password>USER_PASSWD</password>
  </server>
</servers>
<mirrors>
    <mirror>
      <id>nexus-release</id>          <---THIS
      <mirrorOf>*</mirrorOf>
      <url>http://MY_NEXUS_HOST:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

I guess it doesn't matter which one I use (they're both the same in this case, but that's not necessarily always true).

Upvotes: 25

Related Questions