简体   繁体   中英

Use Nexus repository for Maven

I´m trying to configure my maven to use a Nexus repository. What I´m trying to achieve should be very common: I want to have a Nexus repository working as a proxy for central dependencies and also two repositories for snapshots and releases. There´s plenty of documentation out there, but I am not able to get it running. I edited my settings.xml so that it looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
    http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository>${M2_REPO}</localRepository>
  <servers>
    <server>
      <id>nexus</id>
      <username>myuser</username>
      <password>mypass</password>
      <url>https://snapshoturl</url>
    </server>
    <server>
      <id>nexus-releases</id>
      <username>myuser</username>
      <password>mypass</password>
      <url>https://releaseurl</url>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <url>https://groupurl</url>
      <username>myuser</username>
      <password>mypass</password>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>myprofile</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <url>https://snapshoturl</url>
          <username>myuser</username>
          <password>mypass</password>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
        <!--<repository>
                <id>nexus-releases</id>
                <url>https://releaseurl</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>false</enabled></snapshots>
              </repository>-->
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>https://groupurl</url>
          <username>myuser</username>
          <password>mypass</password>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>myprofile</activeProfile>
  </activeProfiles>
</settings>

But I always get the following error message:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-
plugin:2.7:deploy (default-deploy) on project share.logging: Failed to 
retrieve remote metadata xxx:share.logging:1.0.0-SNAPSHOT/maven-
metadata.xml: Could not transfer metadata 
xxx:share.logging:1.0.0-
SNAPSHOT/maven-metadata.xml from/to p19dai-internal (https://snapshoturl): 
Not authorized , ReasonPhrase:Authorization Required. -> [Help 1]

Can anyone help me here? What am I missing?

The problem is in your pom file. The ID in the "distributionManagement" section needs to match an ID in the settings.xml file's "servers". That's how the deployment credentials are looked up by Maven.

Are you running the mvn build via eclipse or eclipse based IDE? then go to Go to Window --> Preferences look for maven in the list and then user settings give the path to your settings.xml in both the global settings and the user settings and click apply

also set your .m2 repo path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM