nexus3 搭建遇到的一些問題

nexus3的坑

搭建好nexus3後,配置了~/.m2/settings.xml文件,和項目中的pom.xml文件。以下apache

  • settings.xml
<?xml version="1.0" encoding="utf-8"?>
<settings>
    <servers>
        <!-- 這是公司的maven nexus 用戶名密碼 -->
        <server>
            <id>souban-nexus</id>
            <username>打碼處理</username>
            <password>打碼處理</password>
        </server>
        <!-- 這是我本身剛搭建的nexus倉庫 用戶密碼 -->
        <server>
            <id>wooo-nexus</id> <!-- 這裏的id和項目中pom配置的的id應該是同樣的 -->
            <username>打碼處理</username>
            <password>打碼處理</password>
        </server>
    </servers>
    <mirrors>
         <mirror>
            <!-- aliyun 加速器 -->
            <id>aliyun-repository-public</id>
            <name>Maven Repository Manager running on aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <!-- aliyun 加速器 -->
            <id>aliyun-repository-central</id>
            <name>Maven Repository Manager running on aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
</settings>
  • pom.xml 這個pom文件是須要作打包上傳的項目 tensquare_common
....
   <!-- 從哪裏去拉jar包 -->
   <repositories>
       <repository>
           <id>wooo-nexus-snapshots</id>
           <name>release repository</name>
           <url>http://打碼處理/repository/release/</url>
       </repository>
       <repository>
           <id>wooo-nexus-release</id>
           <name>snapshots repository</name>
           <url>http://打碼處理/repository/snapshots/</url>
       </repository>
   </repositories>
   <!-- 須要打包上傳到的目的地 -->
   <distributionManagement>
       <repository>
           <id>wooo-nexus</id>
           <name>release</name>
           <url>http://打碼處理/repository/release/</url>
       </repository>
       <snapshotRepository>
           <id>wooo-nexus</id>
           <name>snapshots</name>
           <url>http://打碼處理/repository/snapshots/</url>
       </snapshotRepository>
   </distributionManagement>
....

新建了兩個format爲maven(group)的倉庫,如圖:maven

image

隨後我在pom文件中作了以下配置url

<repositories>
        <repository>
            <id>wooo-nexus-snapshots</id>
            <name>release repository</name>
            <url>http://打碼處理/repository/release/</url>
        </repository>
        <repository>
            <id>wooo-nexus-release</id>
            <name>snapshots repository</name>
            <url>http://打碼處理/repository/snapshots/</url>
        </repository>
    </repositories>

    <distributionManagement>
        <repository>
            <id>wooo-nexus</id>
            <name>release</name>
            <url>http://手動打碼/repository/release/</url> <!-- 更改了這一行-->
        </repository>
        <snapshotRepository>
            <id>wooo-nexus</id>
            <name>snapshots</name>
            <url>http://手動打碼/repository/snapshots/</url>  <!-- 還有這一行-->
        </snapshotRepository>
    </distributionManagement>

而後再使用mvn deploy命令時, 報了以下的錯:code

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project tensquare_common: Failed to deploy artifacts: Could not transfer artifact io.wooo:tensquare_common:jar:0.0.4-20181116.063410-1 from/to wooo-nexus (http://手動打碼/repository/snapshots/): Failed to transfer file: http://打碼處理/repository/snapshots/io/wooo/tensquare_common/0.0.4-SNAPSHOT/tensquare_common-0.0.4-20181116.063410-1.jar. Return code is: 405, ReasonPhrase: PUT. -> [Help 1]

解決過程太複雜,不過贅述。直接說解決方案吧。我把配置中的url的/repository/snapshots換爲了/repository/maven-snapshots,maven-snapshots如圖: 這個是nexus自帶的倉庫還有一個maven-release也是。orm

image

按照網上的理解是,你建了一個group的倉庫選擇了maven-shapshots會指向該倉庫,因而我就新建了上上個截圖的兩個倉庫,而後在配置文件中配好就死活報錯。 而後把配置改成了這樣之後:server

<repositories>
        <repository>
            <id>wooo-nexus-snapshots</id>
            <name>release repository</name>
            <url>http://手動打碼/repository/release/</url>
        </repository>
        <repository>
            <id>wooo-nexus-release</id>
            <name>snapshots repository</name>
            <url>http://手動打碼/repository/snapshots/</url>
        </repository>
    </repositories>

    <distributionManagement>
        <repository>
            <id>wooo-nexus</id>
            <name>release</name>
            <url>http://手動打碼/repository/maven-release/</url> <!-- 更改了這一行-->
        </repository>
        <snapshotRepository>
            <id>wooo-nexus</id>
            <name>snapshots</name>
            <url>http://手動打碼/repository/maven-snapshots/</url>  <!-- 還有這一行-->
        </snapshotRepository>
    </distributionManagement>

就沒有報錯了,因而我知道問題所在了。 而後我刪了自帶的maven-snapshots和maven-release,自建了下面兩個倉庫:xml

image

配置文件以下:utf-8

<repositories>
        <repository>
            <id>wooo-nexus-snapshots</id>
            <name>release repository</name>
            <url>http://手動打碼/repository/release/</url>
        </repository>
        <repository>
            <id>wooo-nexus-release</id>
            <name>snapshots repository</name>
            <url>http://手動打碼/repository/snapshots/</url>
        </repository>
    </repositories>

    <distributionManagement>
        <repository>
            <id>wooo-nexus</id>
            <name>release</name>
            <url>http://手動打碼/repository/release/</url> <!-- 更改了這一行-->
        </repository>
        <snapshotRepository>
            <id>wooo-nexus</id>
            <name>snapshots</name>
            <url>http://手動打碼/repository/snapshots/</url>  <!-- 還有這一行-->
        </snapshotRepository>
    </distributionManagement>

nexus配置以下,兩個倉庫配置是同樣的。it

image

相關文章
相關標籤/搜索