如果svn已过期,Maven会停止构建

时间:2014-03-13 16:30:53

标签: maven svn maven-3 buildnumber-maven-plugin maven-enforcer-plugin

在阅读了很多SO问题以及其他网站之后,我仍然无法完全解决这个问题。

我们有一个很长的构建周期(10-20分钟),因为有很多依赖项。有时候你会开始构建所有东西都做日期,但是当它完成时,有人会将新的更改推送到远程svn。

我希望Maven在validateverify阶段检查svn在所有相关项目中是否仍然是最新的。

我尝试使用Enforcer插件和Build number插件但尚未成功。执行者似乎可以做这个伎俩,但我还没弄清楚要设置哪些规则。 另一方面,内部版本号插件检查是否没有本地修改,但我认为它不会检查远程更改。

我不认为POM与这个问题非常相关,但是如果有人需要它,或者某些部分请告诉我,我会用它来更新。

2 个答案:

答案 0 :(得分:1)

我会尝试maven-scm-plugin's diff goal和Enforcer的组合。

scm:diff可以配置为将输出写入文件。在没有更改时运行该文件并查看文件有多大,或者,如果没有更改,它是否生成文件。然后,使用Enforcer插件的requireFilesDontExist和/或requireFileSize规则来确保scm:diff输出文件是"无更改"你决定的大小。如果它大于此值,则在此构建期间提交更改。

答案 1 :(得分:1)

经过大量测试后,我找到了另一种解决方案。此解决方案适用于使用SVN并且只希望在构建成功后提交更改的人员,并且需要使用最新版本进行构建。

这样做是从SVN检索最新版本号并更新工作副本。在构建过程结束时,它将再次检查修订号,以确保没有人推动任何更改。

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
    <execution>
        <id>get-svn-local-revision-before</id>
        <phase>validate</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>true</doUpdate>
            <buildNumberPropertyName>buildNumberLocal</buildNumberPropertyName>
            <useLastCommittedRevision>true</useLastCommittedRevision>
        </configuration>
    </execution>
    <execution>
        <id>get-svn-remote-revision-before</id>
        <phase>validate</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <buildNumberPropertyName>buildNumberRemote</buildNumberPropertyName>
            <useLastCommittedRevision>false</useLastCommittedRevision>
        </configuration>
    </execution>
    <!-- Repeat after everything is done -->
    <execution>
        <id>get-svn-remote-revision-after</id>
        <phase>verify</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <buildNumberPropertyName>buildNumberRemote</buildNumberPropertyName>
            <useLastCommittedRevision>false</useLastCommittedRevision>
        </configuration>
    </execution>
</executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
    <execution>
        <id>check-svn-revisions-before</id>
        <phase>process-test-resources</phase>
        <goals>
            <goal>enforce</goal>
        </goals>
        <configuration>
            <rules>
                <evaluateBeanshell>
                     <condition>${buildNumberLocal} == ${buildNumberRemote}</condition>
                     <message>[ERROR] Local build (${buildNumberLocal}) doesn't match remote build (${buildNumberRemote})</message>
                </evaluateBeanshell>
             </rules>
             <fail>true</fail>
        </configuration>
    </execution>
    <!-- Repeat after everything is done -->
    <execution>
        <id>check-svn-revisions-after</id>
        <phase>verify</phase>
        <goals>
            <goal>enforce</goal>
        </goals>
        <configuration>
            <rules>
                <evaluateBeanshell>
                    <condition>${buildNumberLocal} == ${buildNumberRemote}</condition>
                    <message>[ERROR] Local build (${buildNumberLocal}) doesn't match remote build (${buildNumberRemote})</message>
                </evaluateBeanshell>
             </rules>
             <fail>true</fail>
        </configuration>
    </execution>
</executions>
</plugin>
相关问题