maven release 插件使用

關(guān)于release與snapshot的區(qū)別這里不再贅述,maven項(xiàng)目在生產(chǎn)環(huán)境部署的時(shí)候一定是需要打release包的。

maven-release-plugin 可用于構(gòu)建release版本項(xiàng)目,實(shí)現(xiàn)自動(dòng)打tag、遞增版本號(hào)、分發(fā)release版本jar包至倉庫。

pom.xml配置:

<!--git 遠(yuǎn)程倉庫配置-->
<scm>
        <connection>scm:git:http://項(xiàng)目git地址</connection>
        <url>項(xiàng)目git地址(不加'.git后綴')</url>
        <developerConnection>scm:項(xiàng)目git地址</developerConnection>
 </scm>

 <!--構(gòu)建配置-->
 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
        </plugins>
    </build>
   
    <!--分發(fā)配置-->
    <distributionManagement>
        <repository>
            <id>deploymentRepo</id>
            <name>releases</name>
            <url>http://somehost/repository/maven-releases/</url>
            <uniqueVersion>true</uniqueVersion>
        </repository>
        <snapshotRepository>
            <id>deploymentRepo</id>
            <name>snapshots</name>
            <url>http://somehost/repository/maven-snapshots/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>

由于會(huì)將構(gòu)建的包分發(fā)到倉庫,需要在maven的配置文件setting.xml下加入權(quán)限配置:

    <server>
      <id>your id</id>
      <username>your username</username>
      <password>your pass</password>
    </server>

這里最關(guān)鍵的一點(diǎn)是scm節(jié)點(diǎn)配置,無論項(xiàng)目是使用git、svn或是其他版本控制工具,都可以在這里配置,詳細(xì)的配置可參考scms-overview。

下面是一個(gè)項(xiàng)目配置示例:

   <scm>
        <connection>scm:git:http://git-local.bnz.com/srv/bnz-ep.git</connection>
        <url>http://git-local.bnz.com/srv/bnz-ep</url>
        <developerConnection>scm:git:http://git-local.bnz.com/srv/bnz-ep.git</developerConnection>
    </scm>

如果需要跳過單元測試,可以加入?yún)?shù) -Darguments="-DskipTests",直接使用-Dmaven.test.skip=true無效的。

在執(zhí)行mvn release:perform時(shí)默認(rèn)會(huì)生成api文檔,如果默寫注釋不符合規(guī)范的話會(huì)造成構(gòu)建失敗,可以加參數(shù)-DuseReleaseProfile=false取消構(gòu)建api文檔,或則需要根據(jù)規(guī)范書寫注釋。

mvn release:prepare
mvn release:perform

如果在構(gòu)建過程中出現(xiàn)錯(cuò)誤,rollback回滾即可

mvn release:rollback
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,632評(píng)論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,278評(píng)論 6 342
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,163評(píng)論 25 708
  • |-1-更新內(nèi)容[6.從倉庫解析依賴的機(jī)制(重要)] 1Maven倉庫作用 倉庫用來存儲(chǔ)所有項(xiàng)目使用到構(gòu)件,在ma...
    zlcook閱讀 6,464評(píng)論 0 25
  • 時(shí)下,共享經(jīng)濟(jì)成為“新經(jīng)濟(jì)盛宴”,不經(jīng)意間,搞經(jīng)濟(jì)的不談共享經(jīng)濟(jì)就感覺很“l(fā)ow”;搞企業(yè)的不跟共享掛鉤就感覺“o...
    白話勞動(dòng)法閱讀 521評(píng)論 0 1

友情鏈接更多精彩內(nèi)容