Maven发布插件和Nexus在SCM上的流程HowTo

时间:2013-12-31 09:19:07

标签: version-control build-process nexus maven-release-plugin

配置

为了让Maven能够发布到Nexus Repository Server,我们需要通过distributionManagement元素定义存储库信息:

<distributionManagement>
 <repository>
  <id>nexus-releases</id>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
 </repository>
</distributionManagement>

Release流程将与项目的Source Control进行交互 - 这意味着我们首先需要在pom.xml中定义元素:

<scm>
 <connection>scm:git:https://github.com/user/project.git</connection>
 <url>http://github.com/user/project</url>
 <developerConnection>scm:git:https://github.com/user/project.git</developerConnection>
</scm>

或git

<scm>
  <connection>scm:git:git@github.com:user/project.git</connection>
  <url>scm:git:git@github.com:user/project.git</url>
  <developerConnection>scm:git:git@github.com:user/project.git</developerConnection>
</scm>

发布流程使用的标准Maven插件是maven-release-plugin - 此插件的配置是

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-release-plugin</artifactId>
 <version>2.4.2</version>
 <configuration>
  <tagNameFormat>v@{project.version}</tagNameFormat>
  <autoVersionSubmodules>true</autoVersionSubmodules>
  <releaseProfiles>releases</releaseProfiles>
 </configuration>
</plugin>

正是在这个过程中,nexus-staging-maven-plugin用于执行对nexus-releases Nexus存储库的部署

<profiles>
<profile>
  <id>releases</id>
  <build>
     <plugins>
        <plugin>
           <groupId>org.sonatype.plugins</groupId>
           <artifactId>nexus-staging-maven-plugin</artifactId>
           <version>1.5.1</version>
           <executions>
              <execution>
                 <id>default-deploy</id>
                 <phase>deploy</phase>
                 <goals>
                    <goal>deploy</goal>
                 </goals>
              </execution>
           </executions>
           <configuration>
              <serverId>nexus-releases</serverId>
              <nexusUrl>http://localhost:8081/nexus/</nexusUrl>
              <skipStaging>true</skipStaging>
           </configuration>
        </plugin>
     </plugins>
  </build>
</profile>
</profiles>

某些nexus只能通过内部网络访问,如果是这种情况,您不需要在%USER_HOME%/。m2 / settings.xml中配置凭据来访问nexus服务器。如果您的nexus受凭据保护,则必须使用以下命令对其进行配置:

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

发布流程

从包含POM.xml的目录在ur终端中逐步执行接下来的3个命令。每一步都需要结束成功

释放:清洁

删除发布描述符(release.properties)并删除所有备份POM文件

释放:制备

将pom文件中的项目版本更改为完整版本号(删除SNAPSHOT后缀) - 在我们的示例中 - 0.1,运行测试套件,创建此非SNAPSHOT版本的标记并增加版本项目在pom

释放:执行

从SCM签出准备好的发布标记,构建并将发布的代码部署到nexus

0 个答案:

没有答案