简体   繁体   中英

How to get the SVN buildnumber of a particular branch in Maven

I do SVN check out for a tree of multiple branches, and I use the buildnumber plugin to get the SVN revision with "javasvn" implementation provider.

When I try to build a particular branch, it seems that Maven retrieves the revision of the top level folder of the tree, not the revision of that particular branch.

For example:
root revision no.: 100
root/branch1 revision no.: 99
root/branch2 revision no.: 97

In my case, when building branch1, I need 99 for buildnumber, not 100.

I use SVN 1.7.

Here is how I configure the plugin:

<build>

    <finalName>${project.artifactId}-${project.version}-SVN${buildNumber}</finalName>

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <providerImplementations>
                    <svn>javasvn</svn>
                </providerImplementations>
            </configuration>
        </plugin>

Any idea is greatly appreciated.
Thanks

Here's how we do it in our project:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <!-- http://stackoverflow.com/questions/3532135/using-maven-to-output-the-version-number-to-a-text-file -->
                            <!-- Safety -->
                            <mkdir dir="${project.build.directory}"/>

                            <exec executable="svn" output="${basedir}/src/main/filters/svn.properties" dir="..">
                                <arg value="info"/>
                            </exec>
                            <replace file="${basedir}/src/main/filters/svn.properties" token="Last Changed Rev"
                                     value="Last.Changed.Rev"/>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>

That outputs a line in src/main/filters/svn.properties that has Last.Changed.Rev: 22479 in it. We rename Last Changed Rev to Last.Changed.Rev so it's a valid variable name. You can then use that as a filter in other files. You may not need it as a filter, but maybe this example will help you for your needs.

Try using the useLastCommittedRevision configuration which is set to false by default. This should grab the last committed revision instead of the repository revision on the specific module where the pom builds from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM