0

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

我们的构建周期很长(10-20 分钟),因为有很多依赖项。有时会发生,您开始构建所有内容都是最新的,但是在完成时,有人将新的更改推送到远程 svn。

如果 svn 基本上仍然是最新的,我希望 Maven 在所有相关项目上检查validate和阶段。verify

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

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

4

2 回答 2

1

我会尝试结合使用maven-scm-plugin 的 diff 目标和 Enforcer。

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

于 2014-03-13T16:45:01.610 回答
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>
于 2014-03-14T11:23:50.130 回答