刚得到它在一个黑客的方式...但我不是满意。
如果有人会提供一个更好的方法来对maven执行自定义的递归发布过程,我会很乐意改变我的接受程度!
父POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>test-release-parent</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-release-parent</name>
<description>This is the parent pom to test release procedure</description>
<inceptionYear>2014</inceptionYear>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<svn.repository>http://svn.mycompany.com/repo1</svn.repository>
<web.projects>http://www2.mycompany.com/projects</web.projects>
</properties>
<scm>
<developerConnection>scm:svn:${svn.repository}/${project.artifactId}</developerConnection>
<url>${svn.repository}/${project.artifactId}</url>
</scm>
<distributionManagement>
<repository>
<id>ftp.mycompany.com</id>
<name>mycompany Maven Repository</name>
<url>ftp://ftp.mycompany.com/maven-repo</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>www2.mycompany.com</id>
<name>mycompany Maven Repository</name>
<url>http://www2.mycompany.com/maven-repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>www2.mycompany.com</id>
<name>mycompany Maven Repository</name>
<url>http://www2.mycompany.com/maven-repo</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<excludes>
<exclude>javax:javaee-api:*:*</exclude>
<exclude>org.eclipse.persistence:*:*:*</exclude>
<exclude>org.hibernate:hibernate-validator:*:*</exclude>
</excludes>
<rulesUri>http://www.mycompany.com/ruleset.xml</rulesUri>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<configuration>
<source>
String releaseVersion = project.version.substring(0, project.version.indexOf("-"));
String nextVersion;
int index = releaseVersion.lastIndexOf(".");
if(index == -1) nextVersion = (releaseVersion.toInteger() + 1) + "-SNAPSHOT";
else
{
String prefix = releaseVersion.substring(0, index);
String suffix = releaseVersion.substring(index + 1);
nextVersion = prefix + "." + (suffix.toInteger() + 1) + "-SNAPSHOT";
}
ant.exec(failonerror: "true", dir: "${basedir}", executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "validate")
arg(value: "-Prelease-align")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}", executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "initialize")
arg(value: "-Prelease-prepare")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}", executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "deploy")
arg(value: "-Prelease-perform")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
</source>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.6</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>buildall</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
for(d in project.dependencies)
{
if(d.groupId == "com.mycompany" && d.version.endsWith("-SNAPSHOT"))
{
println "installing " + d
ant.exec(failonerror: "true", dir: "${basedir}/../" + d.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "install")
arg(value: "-Pbuildall")
}
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-align</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>initial-updates</id>
<phase>validate</phase>
<goals>
<goal>update-parent</goal>
<goal>use-releases</goal>
<goal>commit</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-prepare</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>release-snapshots</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
if(project.parent != null && project.parent.groupId == "com.mycompany" && project.parent.version.endsWith("-SNAPSHOT"))
{
println "releasing " + project.parent
String releaseVersion = project.parent.version.substring(0, project.parent.version.indexOf("-"));
String nextVersion;
int index = releaseVersion.lastIndexOf(".");
if(index == -1) nextVersion = (releaseVersion.toInteger() + 1) + "-SNAPSHOT";
else
{
String prefix = releaseVersion.substring(0, index);
String suffix = releaseVersion.substring(index + 1);
nextVersion = prefix + "." + (suffix.toInteger() + 1) + "-SNAPSHOT";
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + project.parent.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "validate")
arg(value: "-Prelease-align")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + project.parent.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "initialize")
arg(value: "-Prelease-prepare")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + project.parent.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "deploy")
arg(value: "-Prelease-perform")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
}
for(d in project.dependencies)
{
if(d.groupId == "com.mycompany" && d.version.endsWith("-SNAPSHOT"))
{
println "releasing " + d
String releaseVersion = d.version.substring(0, d.version.indexOf("-"));
String nextVersion;
int index = releaseVersion.lastIndexOf(".");
if(index == -1) nextVersion = (releaseVersion.toInteger() + 1) + "-SNAPSHOT";
else
{
String prefix = releaseVersion.substring(0, index);
String suffix = releaseVersion.substring(index + 1);
nextVersion = prefix + "." + (suffix.toInteger() + 1) + "-SNAPSHOT";
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + d.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "validate")
arg(value: "-Prelease-align")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + d.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "initialize")
arg(value: "-Prelease-prepare")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
ant.exec(failonerror: "true", dir: "${basedir}/../" + d.artifactId, executable: "cmd")
{
arg(value: "/c")
arg(value: "mvn")
arg(value: "deploy")
arg(value: "-Prelease-perform")
arg(value: "-Dversion.release=" + releaseVersion)
arg(value: "-Dversion.next=" + nextVersion)
}
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>final-updates</id>
<phase>initialize</phase>
<goals>
<goal>update-parent</goal>
<goal>use-releases</goal>
<goal>set</goal>
<goal>commit</goal>
</goals>
<configuration>
<newVersion>${version.release}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-perform</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>set-next-snapshot</id>
<phase>deploy</phase>
<goals>
<goal>set</goal>
<goal>commit</goal>
</goals>
<configuration>
<newVersion>${version.next}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<executions>
<execution>
<id>checkin-release</id>
<phase>verify</phase>
<goals>
<goal>checkin</goal>
<goal>tag</goal>
</goals>
</execution>
<execution>
<id>checkin-snapshot</id>
<phase>deploy</phase>
<goals>
<goal>checkin</goal>
</goals>
</execution>
</executions>
<configuration>
<tag>${project.version}</tag>
<message>auto-generated by release process</message>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
,这是一个项目POM使用另一个项目(弄平在工作区的结构)作为依赖性
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.mycompany</groupId>
<artifactId>test-release-parent</artifactId>
<version>1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-release-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>maven project to test a release process</description>
<inceptionYear>2014</inceptionYear>
<url>${web.projects}/${project.artifactId}</url>
<repositories>
<repository>
<id>www2.mycompany.com</id>
<name>mycompany Maven Repository</name>
<url>http://www2.mycompany.com/maven-repo</url>
</repository>
</repositories>
<scm>
<developerConnection>scm:svn:${svn.repository}/${project.artifactId}/trunk</developerConnection>
<url>${svn.repository}/${project.artifactId}/trunk</url>
</scm>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>test-release-dependency</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
只需运行
mvn <some-phase> -Pbuildall
到当前项目执行<some-phase>
,执行上所有拥有和引用快照(父母和依赖性)
和
mvn groovy:execute
执行释放全资和引用的快照
背后的想法:
- 程序发布:
- 更新父版本(如果存在)
- 更新快照依赖性是否存在
- 如果父拥有和快照
- 每个拥有和快照依赖性
- 更新父版本(现在必须存在)
- 更新owne d和快照依赖(现在必须存在)
- 集项目发行版本(即从1.0.0-快照1.0.0)
- 提交修改到SCM供应链管理
- 标签冻结执行所有的Maven生命周期相直到部署
- 项目集下一版本(即从1.0.0到1.0.1-SNAPSHOT)
- 提交修改到SCM再次
你在'聚合器'下了解什么?您应该考虑真正与多模块构建工作,并根据您的真实结构更改SVN中的结构。版本共享是什么意思? – khmarbaise
@khmarbaise多模块应该使用时,模块将*总是*一起发布,而不是作为一个简单的命令建立一个简单的。根据我的经验,*永远*很少是这种情况 –
@NickHolt我没有说过用它作为捷径。它看起来越来越像一个多模块构建,而操作正试图绕过它。 – khmarbaise