使用nexus3.19搭建自己的maven私服


  怎么安裝參見CentOS6.9安裝Nexus3.19 ,接下來就是如何配置。打開我們安裝后的nexus界面,用admin賬號登陸,點擊Server administration and configuration按鈕:

 

 

 

  點擊Repository

 

 

 

  我們可以看到nexus默認給我建好了一些倉庫,其中包括3類:代理proxy,倉庫組group和宿主host。

  代理用來指向遠程倉庫的,如中央倉庫,但畢竟國內的阿里雲倉庫比國外要快許多,所以我們自己建一個新的代理倉庫。點擊Create Repository:

 

 

   

  選擇maven2(proxy):

 

 

 

  輸入倉庫名和阿里雲的遠程倉庫地址(http://maven.aliyun.com/nexus/content/groups/public):

 

 

 

  拉到最下面點擊Create Repository,返回上一層界面:  

 

 

  接着我們創建宿主倉庫,宿主倉庫跟我們的項目相關,用於上傳我們打出來的包,分發布Release和快照Snapshot兩種,所以我們就建兩個宿主倉庫,過程同上:

 

 

 

 

 

   最后我們再創建一個倉庫組,倉庫組就像數據庫的視圖一樣,能把多個倉庫聚合起來用,記得把aliyun放在maven-central上面,這樣才能優先找阿里雲的構件:

 

 

 

 

 

  ok,現在我要的倉庫都弄好了,接着配置maven的全局設置setting.xml文件。在這之前,還得新建一個用戶給開發用。nexus3.19的默認用戶有兩種:admin(能配置倉庫、查詢和上傳構件)和anonymous(只能查構件):

 

 

  我們新增一個角色deployment用於構建查詢和上傳,剝離admin的倉庫管理能力,免得開發人員瞎搞。先新增角色:

 

 

 

 

  再回去用戶那里新增一個deployment用戶:

 

 

 

 

  

 

  最后,我們在setting中添加我們新加的宿主倉庫的認證(我設置deployment用戶的密碼就是deployment123),配置鏡像,讓所有maven構建都走到鏡像,經由鏡像去請求倉庫組,最后請求到我們配置的宿主倉庫和代理倉庫,大概脈絡如下:

                                   +---------------aliyun(proxy) :下載開源jar包

maven -> nexus(group) ->  |---------------nexus-releases(host) :項目上傳release的jar包,下載本地上傳的jar包

                                           +---------------nexus-snapshots(host):項目上傳snapshot的jar包,下載本地上傳的jar包

   新建一個setting文件setting_nexus.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>E:/Users/wulf/.m2/repository</localRepository>

    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>nexus repository</name>
            <url>http://111.11.11.11/repository/nexus-group</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>

    <!-- 激活配置 -->
    <activeProfiles>       
        <activeProfile>nexus</activeProfile>
    </activeProfiles>    
    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>      
                    <url>http://111.11.11.11:17407/repository/aliyun</url>                    
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>                    
                </repository>               
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>      
                    <url>http://111.11.11.11:17407/repository/aliyun</url>                    
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>    
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>


    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server> 
    </servers>

</settings>

 

   新建一個maven項目(spring boot項目),指定我們新增setting文件:

 

   只需要往按默認生成的pom文件中加入上傳jar包的宿主倉庫即可:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.wlf</groupId>
    <artifactId>spring-cloud-plugin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-cloud-plugin</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <url>http://111.11.11.11:17407/repository/nexus-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://111.11.11.11:17407/repository/nexus-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 

  跑一個deploy,看下maven執行日志:

Downloading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/maven-metadata.xml
Uploading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/spring-cloud-plugin-0.0.1-20201017.010507-1.jar
Uploaded: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/spring-cloud-plugin-0.0.1-20201017.010507-1.jar (8033 KB at 1523.3 KB/sec)
Uploading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/spring-cloud-plugin-0.0.1-20201017.010507-1.pom
Uploaded: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/spring-cloud-plugin-0.0.1-20201017.010507-1.pom (3 KB at 4.9 KB/sec)
Downloading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/maven-metadata.xml
Uploading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/0.0.1-SNAPSHOT/maven-metadata.xml (776 B at 2.9 KB/sec)
Uploading: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/maven-metadata.xml
Uploaded: http://111.11.11.11:17407/repository/nexus-snapshots/com/wlf/spring-cloud-plugin/maven-metadata.xml (286 B at 1.4 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.136 s
[INFO] Finished at: 2020-10-17T09:05:13+08:00
[INFO] Final Memory: 25M/210M
[INFO] ------------------------------------------------------------------------

 

  去看一眼nexus的界面,nexus-snapshots的包成功打上去了:

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM