Maven 自動打包上傳到私服 Nexus

配置

        Maven獲取jar的默認順序是
        
        1. Releases 在發佈庫裏面查找(主要用於穩定版)
        2. Snapshots 在快照庫裏面查找(和上面的區別就是在pom加了個<version>0.0.5-SNAPSHOT</version>,主要用於開發階段)
        3. 3rd party 不是我們自己開發的,也在中央庫找不到的,就要到這裏手動上傳包到私服。
        4. Central 到中央庫查找。


        上傳私服 pom.xml 配置
1
2
3
4
5
6
7
8
9
10
<distributionManagement >
    <repository >
        <id >releases </id >
   </repository >
   <snapshotRepository >
        <id >Snapshots </id >
   </snapshotRepository >
</distributionManagement 

        settings.xml 配置
1
2
3
4
5
6
7
8
9
10
11
12
<servers>
    <server
       <id>releases</id
       <username>admin</username
       <password>qsapwd</password
    </server
    <server
       <id>Snapshots</id
       <username>admin</username
       <password>qsapwd</password
    </server>  
</servers
        
        打包源碼 pom.xml 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<build>
        <plugins>
            <plugin<!-- 打jar包 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <excludes>
                        <exclude>**/*.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin<!-- 打源碼 -->
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-source-plugin</artifactId>  
               <version>2.4</version>
                <configuration>  
                    <attach>true</attach>  
                </configuration>  
                <executions>  
                    <execution>  
                        <phase>compile</phase>  
                        <goals>  
                            <goal>jar</goal>  
                        </goals>  
                    </execution>  
                </executions
            </plugin> 
        </plugins>
    </build>

Maven 打源碼包,並上傳私服

        1. 使用命令行

        cmd 進入到項目根目錄執行:mvn clean source:jar package 會生成兩個jar,其中有一個是源碼的jar,分別使用相同的groupId和artifactId。

        也可以直接,打包並上傳私服,使用命令:deploy -e

        2. 使用Eclipse

        右擊項目 Run as →Maven bulid,在Goals輸入deploy -e。
        

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章