1. 程式人生 > >Maven + Gogs + Nexus 實現版本管理 + 程式碼模組開發管理

Maven + Gogs + Nexus 實現版本管理 + 程式碼模組開發管理

Gogs:能夠實現fork + 程式碼提交 + 程式碼框架

Nexus:進行jar包的版本管理,私服下載jar包共享jar包

Maven:在客戶端進行模組管理和批量操作

1. 本地maven倉庫配置配置settings.xml私服地址

settings.xml

<project>
  <!--  使用者名稱密碼 -->
  <servers>
    <server>    
       <id>nexus-releases</id>
       <username>admin</username>
       <password>xxxxxxx</password>    
    </server>
    <server>    
       <id>nexus-snapshots</id>    
       <username>deployment</username>    
       <password>xxxxxxx</password>    
    </server>
  </servers>
  <!-- 映象倉庫配置 -->
  <mirrors>
      <mirror>
      <id>repo-nexus</id>
      <url>http://127.0.0.1:8081/nexus/content/repositories/central/</url>
      <mirrorOf>central</mirrorOf>
     </mirror>
  </mirrors>
    <!-- 私服配置 -->
    <profile> 
        <id>repo</id>  
        <activation> 
            <activeByDefault>true</activeByDefault> 
        </activation>  
        <repositories> 
            <repository> 
            <id>repo</id>  
            <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>  
            <releases> 
                <enabled>false</enabled> 
            </releases>  
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
            </repository> 
        </repositories>  
        <pluginRepositories> 
            <pluginRepository> 
            <id>repo</id>  
            <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>  
            <releases> 
                <enabled>false</enabled> 
            </releases>  
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
            </pluginRepository> 
        </pluginRepositories> 
        </profile>
    </profiles>
</project>

2. 建立maven專案,修改配置scm、maven-release-plungin, 推送到倉庫中

pom.xml

<project>
    <!-- 構建管理配置私服 -->
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release FRepository</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Shapshots Repository</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <!-- git的版本管理控制 -->
    <scm>
        <connection>scm:git:http://127.0.0.1:3062/wulonghuai/maven_module.git</connection>
        <developerConnection>scm:git:http://127.0.0.1:3062/wulonghuai/maven_module.git</developerConnection>
        <url>http://127.0.0.1:3062/wulonghuai/maven_module/src/master</url>
    </scm>

    <!--  外掛配置 -->
    <build>
        <plugins>
            <!-- maven release 釋出外掛-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>
[email protected]
{project.version}</tagNameFormat> <username>username</username> <password>password</password> <branchBase>master</branchBase> </configuration> </plugin> </plugins> </build> </project>

3. 使用命令進行快照版本釋出

在mave專案目錄下,對應配置的pom.xml檔案下面

clean package -U deploy -Dmaven.test.skip=true
# BUILD SUCCESS即為上傳成功

4. 使用命令進行映象版本釋出

第一步:release:prepare:打包前的準備工作

  1. 輸入對應的release需要打包的版本嘻嘻,如果不輸入有預設的內容
  2. 將需要記錄和準備的內容快取到pom.xml目錄下的release.properties檔案中
  3. 在本地和遠端倉庫的git中打上對應版本的tag
    先確認原生代碼全部提交了,否則會失敗。執行prepare的時候會執行單元測試,失敗也會回滾
# 執行釋出準備命令
release:prepare
# 確認maven倉庫的release版本號,回車為預設值
What is the release version for "mavenmodule"? (com.wlh:mavenmodule) 1.3: : 
# 確認scm中的倉庫的tag標籤版本號,回車為預設值
What is SCM release tag or label for "mavenmodule"? (com.wlh:mavenmodule) v1.3: : 
# 確認下一個開發版本的快照版本編號
What is the new development version for "mavenmodule"? (com.wlh:mavenmodule) 1.4-SNAPSHOT: : 

後悔藥:release:rollback
在順北階段發生錯誤的時候,就需要這個命令了,這個命令執行會去做以下這些事情

  1. 刪除線上git庫tag但是本地沒有被刪除,需要手動使用git -d xxx 進行刪除,否則下次準備會失敗
  2. 刪除之前快取在pom.xml統一目錄下的配置
# 執行回滾命令
release:rollback
# 會降本的的分支進行刪除,但是伺服器上的分支不會刪除,需要手動通過工具進行刪除命令
release:prepare

最後一步:release:perform
如果確認無誤了以後,就可以執行perform命令了

  1. 驗證程式碼合法性
  2. 將你之前的1.0-SNAPSHOT改為1.1-SNAPSHOT
  3. 將1.0版本deploy至scm配置的nexus release庫中
  4. 將程式碼source。jar版本 javacode。jar打包上傳至nexus庫
# 將原始碼上傳到伺服器了
release:perform

題外話

去spring的框架上面看了下,springboot還是用maven進行管理依賴,而spring框架就是用gradle。
後來看了下dubbo也是用maven外掛的方式進行版本釋出,所以看來路子是沒有錯誤的,哈哈哈。


華為雲和Sonatype聯合釋出的中國官方Maven中央倉庫

【maven實戰】42-使用maven-release-plugin自動化版本釋出

外掛安裝相關文章

maven最佳實踐:版本管理

官方外掛地址:Maven Release Plugin

Nexus入門指南