maven之SCM(Software Configuration Managemen),maven-release-plugin,distributionManagement与pluginReposi...

一. 简介

 在项目开发过程中,通常开发阶段会包含以下几个步骤:

 1. 将所有的代码提交到版本管理库(SVN,GIT)或者是打上对应的标签。

 2. 从SVN下载源码

 3. 构建应用

 4. 存储构建输出war,ear或者jar包到网络上指定位置。

 5. 从网络上获取对应的包信息。

 6. 及时更新文档以及更新版本号,

 基于上述步骤:一般需要一个版本管理库(SVN,CVS,GIT);仓库构建和发布(maven), 仓库管理软件(nexus)。其中maven通过SCM插件对其进行版本管理软件进行构建操作。通过distributionManagement发布到对应的网络目录下。

二 SCM插件

SCM主要用于从版本管理库中获取对应的最新版本信息,其主要包括两个链接:
 1. developerConnection:用于指定开发者的链接。
 2. connection:用于发布的链接
 其主要配置格式如下:
scm:svn:http://somerepository.com/svn_repo/trunk
<service name>:<scm implementation>:<repository url>
完整例子:
<project>
  ...
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>SCM Sample Project</name>
  <url>http://somecompany.com</url>
  <scm>
    <connection>scm:svn:http://somerepository.com/svn_repo/trunk</connection>
    <developerConnection>scm:svn:https://somerepository.com/svn_repo/trunk</developerConnection>
    <url>http://somerepository.com/view.cvs</url>
  </scm>
  ...
</project>
通过配置如下脚本,使其更改生效
mvn scm:checkin -Dmessage="code log" #code commit
mvn scm:update #update code
通过mvn的操作将代码进行了同步更新操作。接下来我们需要将上述代码打包发布出去,该maven-release-plugin登场!
三 maven-release-plugin
 该插件的主要功能是通过mavn自动发布项目,减少人工干预。它依赖于POM的SCM信息。其主要包括的阶段1. 准备阶段;2执行阶段;3.回滚,4清楚。
其主要配置信息如下:
  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>x.x.x</version>
        <configuration>
          <username>***</username>
          <password>***</password>
        <tagBase>${svn_url}/tags</tagBase>
          <releaseProfiles>release</releaseProfiles>
       </configuration>
      </plugin>
其执行命令顺序如下:

 mvn release:prepare
Maven会进入交互模式,询问需要发布release的版本(默认是将当前版本的“-SNAPSHOT去掉”);然后询问发布后snapshot版本的版本号(默认当前版本增加一位小版本号);直接回车即可确认。
然后插件开始工作,主要进行的操作有:
A) 替换父工程和子模块的pom.xml中的version字段为1.0.5;然后在本地git仓库当前分支Commit一个版本
B) 在本地git仓库,创建一个tag,默认命名为XXX-1.0.5
C) 再将父工程和子模块的pom.xml中的version字段替换成1.0.6-SNAPSHOT;然后本地git仓库当前分支再Commit一个版本
D) 将以上本地版本push到git remote仓库

mvn release:perform 主要进行的操作是将第一步生成的tag clone到本地,然后对其进行build和deploy操作,完成之后能看到maven release仓库中已经有了对应的版本
mvn release:clean  这一步将上述过程中生成的临时文件删除
创建分支参考: http://maven.apache.org/maven-release/maven-release-plugin/examples/branch.html
(如果发布snapshot,只需要执行 mvn clean deploy即可
当上述稳定版本发布之后,如何快速的将其加入到对应的maven仓库(nexus)中,需要该轮到distributionManagement了。
四. distributionManagement
 maven仓库分为两种:快照仓库(snapshot reposity)与发布仓库(release reposity).快照仓库用于保存项目的不稳定版本。发布仓库既保存稳定版本。一般发布版本需要在版本号后加入-SNAPSHOT(要大写)。其详细列子如下:
 <distributionManagement>
    <repository>
        <id>oss</id>
        <url>http://127.0.0.1:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>oss</id>
        <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
其中上面的id对应%M2_HOME%\conf\settings.xml的<service>节点,配置如下:
<servers>
    ...
    <server>
        <id>oss</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    ...
</servers>
通过运行以下命令进行发布
mvn release:clean release:prepare release:perform

四 pluginRepositories

pluginrepositories:主要是maven用来解决插件依赖。这个需要在setting.xml火灾在pom中配置。 
  repository  :其他的手工依赖需要依靠需要使用reposity(例如 parant pom.xml)等。
其代码如下
<profile>
	 
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
			
            <repositories>
                <repository>
                    <id>nexus-server@public</id>
                    <url>${url}/content/repositories/releases</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-server@public-snapshots</id>
                    <url>${url}/repositories/snapshots</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
			
	 
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-server@public</id>
                    <url>${url}/repositories/releases</url>
                    <snapshots>
                        <enabled>false</enabled>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories> 
		 
        </profile>



                        http://maven.apache.org/




 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.apache.maven.plugins:maven-clean-pluginMaven的一个插件,用于清理项目目录中生成的文件和目录。它的版本号为3.1.0。 该插件的作用是在构建过程中清理项目目录,以便重新构建项目时能够保持干净的状态。它通常用于删除编译生成的类文件、资源文件以及其他构建过程中生成的临时文件。 如果你遇到了"Cannot resolve plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0"或"Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean"的错误,可能是由于以下原因导致的: 1. 插件依赖问题:可能是由于Maven无法解析或下载maven-clean-plugin的依赖导致的。你可以尝试清理本地Maven仓库并重新下载依赖。 2. 版本不匹配:可能是由于你的项目中指定的maven-clean-plugin版本与实际可用的版本不匹配导致的。你可以尝试更新插件的版本或者检查你的项目配置文件中是否指定了正确的插件版本。 3. 文件权限问题:可能是由于Maven无法删除目标目录中的文件或目录导致的。你可以尝试手动删除目标目录中的文件或目录,并确保Maven具有足够的权限来执行清理操作。 以下是一个示例的pom.xml文件中配置maven-clean-plugin的例子: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> <configuration> <!-- 配置插件的参数 --> </configuration> </plugin> </plugins> </build> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值