DeveloperWeb

  Dashboard > GX DeveloperWeb > ... > Best Practices > Maven and Source Control Management in Subversion
Maven and Source Control Management in Subversion Log In | Sign Up   View a printable version of the current page.

Added by patricka@gx.nl , last edited by patricka@gx.nl on Nov 19, 2009  (view change)
Labels: 

Maven is being used to build WCB's from source code. As a good developer, you are using a source control management system (SCM, also known as version control system) to keep track of your source code. (You are using a version control system, right?!?)

Maven can help you tagging your WCB releases properly. This document describes how to get Maven working with Subversion, although the instructions can be tweaked to work with any source control mechanism.

Usually you have a file structure like below in your repository:

testpresentation/
    tags/
        testpresentation-1.0.0/
        testpresentation-1.0.1/
        testpresentation-1.0.2/
        testpresentation-1.0.3/
    trunk/
        changelog.txt
        pom.xml                  <-- Version: 1.0.4-SNAPSHOT
        readme.txt
        src/

Maven can be instructed to automatically create a new release tag, increase the version number in the trunk and commit the changes.

Get the right tools

In order for Maven to work with Subversion, it needs access to command line clients. If you are using TortoiseSVN, this means you need to install the command line client "svn". You can get this from http://subversion.tigris.org/getting.html#windows.

Change the pom.xml

First of all, the version in your trunk is expected to be named as "-SNAPSHOT". This only makes sense; it is not an official release.

So change your pom.xml to read:

  <groupId>com.test</groupId>
  <artifactId>testpresentation</artifactId>
  <version>1.0.11-SNAPSHOT</version>

Next, make your SCM known to Maven by adding the information to the pom.xml:

...
       </properties>
       <packaging>osgi-bundle</packaging>
       <scm>
           <connection>scm:svn:svn+ssh://subversion.test.com/projects/testpresentation/trunk</connection>
           <developerConnection>scm:svn:svn+ssh://subversion.test.com/projects/testpresentation/trunk</developerConnection>
           <url>scm:svn:svn+ssh://subversion.test.com/projects/testpresentation/trunk</url>
       </scm>
       <build>
           <plugins>
...

Last, configure the release plugin to let Maven know where to tag releases. Add this bit of text to the build plugins section of the pom.xml:

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                        <tagBase>svn+ssh://subversion.test.com/projects/testpresentation/tags</tagBase>
                        <scmCommentPrefix>[sandbox] release:</scmCommentPrefix>
                </configuration>
        </plugin>

Note that the <tagBase> is almost the same as the <developerConnection>, but it is missing the "scm:svn:" prefix and has "/tags" at the end instead of "/trunk".

Preparing the release

Now that the pom.xml contains all instructions for Maven, you can prepare and perform the release:

mvn release:prepare

If you are using an alternative "settings.xml", you will have to make sure the arguments are passed on to forked Maven processes:

mvn -s C:\GX\WebManager9\settings.xml -Darguments="-s C:\GX\WebManager9\settings.xml\settings.xml" release:prepare

Maven will ask for some input; it is safe to press "Enter" and accept the defaults.
If all goes well, a new tag will be created in the "tags" directory, which you can check by doing "svn update" in that directory.

Also, a few extra files will have been created after the "release:prepare":

testpresentation/
    tags/
        testpresentation-1.0.0/
        testpresentation-1.0.1/
        testpresentation-1.0.2/
        testpresentation-1.0.3/
        testpresentation-1.0.4/     <-- New, appears after doing "svn update"
    trunk/
        changelog.txt
        pom.xml                     <-- Version changed to 1.0.5-SNAPSHOT
        pom.xml.releaseBackup       <-- New
        readme.txt
        release.properties          <-- New
        src/
        target/                     <-- New




Performing the release

Now that the release has been prepared, it can be performed. This will build the WCB, remove the extra files that have been created and put release files in the target directory.

mvn release:perform

If you are using an alternative "settings.xml", you will have to make sure the arguments are passed on to forked Maven processes:

mvn -s C:\GX\WebManager9\settings.xml -Darguments="-s C:\GX\WebManager9\settings.xml" release:perform

Or, if you want to make a specific release:

mvn -s C:\GX\WebManager9\settings.xml -Darguments="-s C:\GX\WebManager9\settings.xml" release:perform
    -DconnectionUrl=scm:svn:svn+ssh://subversion.test.com/projects/testpresentation/tags/testpresentation-1.0.3

After the build, the directory will look like:

testpresentation/
    tags/
        testpresentation-1.0.0/
        testpresentation-1.0.1/
        testpresentation-1.0.2/
        testpresentation-1.0.3/
        testpresentation-1.0.4/
    trunk/
        changelog.txt
        pom.xml                               <-- Version: 1.0.5-SNAPSHOT
        readme.txt
        src/
        target/
            testpresentation-1.0.4-dist.zip   <-- New
            testpresentation-1.0.4.jar        <-- New

In effect, Maven has created new release files and has tagged the release properly.

Troubleshooting

SCM not working

The SCM URL that you are using in the "pom.xml" file for "<connection>", "<developerConnection>", "<url>" and "<tagBase>" must match the one that is used on disk exactly, or you will get errors.

If you are using TortoiseSVN, you can right click on the directory and examine the SVN URL. Is the URL using the same host name and the same path?

If there is a difference, either edit the "pom.xml" or use "svn switch" to align the directory with the "pom.xml".

For example, let's assume the following:

  • the directory is using "svn+ssh://user@subversion.test.com/projects/testpresentation/trunk",
  • the "pom.xml" is using "svn+ssh://subversion.test.com/projects/testpresentation/trunk"

In this case, editing the "pom.xml" is not preferred as it is correctly using a general URL instead of a user-specific one. So you will want to use "svn switch" to correct the local directory as follows:

svn switch
     --relocate svn+ssh://user@subversion.test.com/projects/testpresentation/trunk
      svn+ssh://subversion.test.com/projects/testpresentation/trunk



Doing release:prepare twice

If you want to do the "release:prepare" again, you can use the command below to ignore the created files:

mvn release:prepare -Dresume=false

 Alternatively, you can clean up the files from a previous "release:prepare" yourself:

mvn release:clean
del pom.xml
svn update
mvn release:prepare

Missing Maven plugins

You may be missing Maven plugins, which you will notice from errors like this:

[INFO] NOTE: Maven is executing in offline mode. Any artifacts not already in your local
[INFO] repository will be inaccessible.
[INFO]
[INFO] [INFO] Scanning for projects...
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Building Unnamed - com.gxwebmanager.test:testpresentation:osgi-bundle:1.0.1
[INFO] [INFO]    task-segment: [deploy, site-deploy]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] BUILD ERROR
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Failed to resolve artifact.
[INFO]
[INFO] GroupId: org.apache.maven.plugins
[INFO] ArtifactId: maven-source-plugin
[INFO] Version: 2.0.3
[INFO]
[INFO] Reason: System is offline.
[INFO]
[INFO]   org.apache.maven.plugins:maven-source-plugin:pom:2.0.3
[INFO]

 As Maven notes: the system is offline. The cause lies in your "settings.xml", which instructs Maven to work offline. Make sure you set <offline> to "false", which will enable Maven to automatically download necessary plugins:

    <localRepository>C:/GX/WebManager9/maven2-repository</localRepository>
    <offline>false</offline>

Missing command line arguments

It is possible that the arguments on the command line are not automatically passed to forked instances of Maven. You can recognize forked instances by multiple "[INFO]" statements on the same line. This is the case in the example above, as can be seen by the "[INFO] [ERROR] BUILD ERROR" message.

To force the passing of commandline arguments to forked instances, you can use '-Darguments="..."', e.g.:

mvn -s C:\GX\WebManager9\settings.xml -Darguments="-s C:\GX\WebManager9\settings.xml" release:perform




Links

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators