zoukankan      html  css  js  c++  java
  • 【运维技术】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>v@{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入门指南

  • 相关阅读:
    linux下启动和关闭网卡命令及DHCP上网
    python 编码问题
    paddlepaddle
    Convolutional Neural Network Architectures for Matching Natural Language Sentences
    deep learning RNN
    Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记
    Python IO密集型任务、计算密集型任务,以及多线程、多进程
    EM 算法最好的解释
    tensorflow 调参过程
    tensorflow 学习纪录(持续更新)
  • 原文地址:https://www.cnblogs.com/fly-piglet/p/9919321.html
Copyright © 2011-2022 走看看