RSS feed
All(28) Eclipse(4) Java(5) JDBC(5) JSP(3) Maven(7) Personal (1) Spring(3) Tomcat(5)
<< Eclipse Performance - JVM Setttings and Turning Paging Off in Windows | Home | How to handle redeploy of java WARs to tomcat5.5 on Windows and avoid jar file locking >>

Using the Maven SCM Plugin to integrate Maven2 and Subversion

How to configure your maven pom.xml to integrate subversion and maven using mvn-scm-plugin

I am using Maven’s SCM plugin to integrate Subversion and Maven.

mvn-scm-plugin is meant to be an abstraction layer over the top of several source control systems

For reference:

http://maven.apache.org/scm/plugins/usage.html

Also great free Maven 2 PDF book avaliable at theserverside.com (although not much scm plugin coverage here still good for basic maven 2 concepts)

http://www.theserverside.com/news/thread.tss?thread_id=40126

 

The goal here is to do an svn update before a mvn deploy and a svn commit only after a successful run of the tests via mvn and after every mvn deploy. This will prevent mvn deploys from being done without svn updates and svn checkins of the code into the subversion repository. I had tried this about a year or so ago with this same plugin and had problems. After upgrading maven and subversion I was able to get this to work with some issues. I thought I would show what the results were and what I did in the pom.xml to get this to work. I tried to find an example pom which integrated this well and it took me some time on google. Hoefully this will help you if youre doing the same.

 

Main assumptions are:

  1. Your using subversion (although another scm supported source control system should work analogously)
  2. Your using Maven 2
  3. Your have tests that run during the test process for maven. Junit is what we use but another framework should be the same as long as it happens during maven lifecycle.

 

There are two main commands you want to get to work for mavens SCM plugin:

mvn scm:update

mvn -Dmessage="test" scm:checkin

 

First Off I had to upgrade mvn from 2.0.4 to 2.0.8

I also upgraded my subversion windows client from 1.3.1 to 1.4.6

Detailed Install Directions for install and update are below:

 

 

Detailed Instructions for install/upgrade of Subversion and Maven

 

I had to upgrade maven and subversion which we havent upgraded since we started using them.

 

  1. Upgraded Maven from 2.0.4 to 2.0.8.

Follow instructions at maven site

http://maven.apache.org/download.html

 

Install maven to

C:\Program Files\Apache Software Foundation\apache-maven-2.0.8

 

  1. Make sure and change your mvn_exec variable in your external tools in eclipse
screenshot

Also change your environment variables

MAVEN_HOME= C:\Program Files\Apache Software Foundation\apache-maven-2.0.8

PATH replace maven portion with C:\Program Files\Apache Software Foundation\apache-maven-2.0.8\bin

 

Install windows command line client for subversion

and make sure its bin is in your path

for the scm plugin from maven to work with subversion

otherwise you will get

'svn' is not recognized as an internal or external command... error

 

  1. I upgraded the subversion client from 1.3.1 to 1.4.6.

http://subversion.tigris.org/project_packages.html

svn-1.4.6-setup.exe

installs over the top of existing installation

 

  1. cmd window and type to verify version upgrade

mvn -version

svn --version

 

Example Pom.xml

 

The items in bold are those that were added to the pom.xml of my project for the mvn-scm-plugin 

 

<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cms</groupId>

  <artifactId>aircore</artifactId>

  <packaging>jar</packaging>

  <version>1.0-SNAPSHOT</version>

  <name>aircore</name>

  <url>http://maven.apache.org</url>

  <!-- the scm url can be grabbed from your eclipse projects properties under subversion if your already using subclipse-->

  <scm>

    <connection>scm:svn:http://myserver/air/java/aircore/trunk</connection>

    <url>http:// myserver/air/java/aircore/trunk</url>

  </scm>

  <build>

       <sourceDirectory>src/main/java</sourceDirectory>

              <testSourceDirectory>src/test/java</testSourceDirectory>

       <resources>

                     <resource>

                           <directory>src/main/java</directory>

                           <includes>

                                  <include>**/*.xml</include>

                                  <include>**/*.properties</include>

                           </includes>

                     </resource>

              </resources>

              <testResources>

                     <testResource>

                           <directory>src/test/java</directory>

                           <includes>

                                  <include>**/*.xml</include>

                                  <include>**/*.properties</include>

                           </includes>

                     </testResource>

              </testResources>

       <plugins>

                     <plugin>

                           <artifactId>maven-compiler-plugin</artifactId>

                           <configuration>

                                  <source>1.5</source>

                                  <target>1.5</target>

                           </configuration>

                     </plugin>

                     <plugin>

                           <groupId>org.apache.maven.plugins</groupId>

                           <artifactId>maven-scm-plugin</artifactId>

                           <version>1.0</version>

                           <configuration>

                                  <connectionType>connection</connectionType>

                                  <message>MVN:message</message><!-- woudl be nice to have some way to enter this in via a popup -->

                           </configuration>

                           <executions>

                                  <!-- svn update -->

                                  <execution>

                                         <id>update</id>

                                         <phase>generate-sources</phase>

                                         <goals>

                                                <goal>update</goal>

                                         </goals>

                                  </execution>

                                  <!-- svn commit -->

                                  <execution>

                                         <id>checkin</id>

                                         <phase>deploy</phase>

                                         <goals>

                                                <goal>checkin</goal>

                                         </goals>

                                  </execution>

                           </executions>

                     </plugin>

                     <plugin>

                         <groupId>org.apache.maven.plugins</groupId>

                         <artifactId>maven-eclipse-plugin</artifactId>

                         <version>2.4</version>

                           <executions>

                                  <!-- regenerate the eclipse .project file -->

                                  <execution>

                                         <id>eclipse</id>

                                         <phase>deploy</phase>

                                         <goals>

                                                <goal>eclipse</goal>

                                         </goals>

                                  </execution>

                           </executions>

                     </plugin>

       </plugins>

       </build>

What the output looks like when you do a mvn install or mvn deploy

I run the following maven external commands from eclipse.

Eclipse External Tools Configuration 

Variable ${maven_exec} is defined as

C:\Program Files\Apache Software Foundation\apache-maven-2.0.8\bin\mvn.bat

 

 

I also configure the refresh tab on my external tools to:

Refresh resrouces after completion

for The project containing the selected resource.

 

 

 

Lets take a look at the output from two maven commands with the above pom.xml

mvn –U clean install

mvn –U clean deploy

 

Basically here is what you will see.

 

During both clean and install scm:update (in bold below) is doing subversion update during the generate-sources phase

 

[INFO] ------------------------------------------------------------------------

[INFO] Building aircore

[INFO]    task-segment: [clean, deploy]

[INFO] ------------------------------------------------------------------------

[INFO] artifact org.apache.maven.plugins:maven-clean-plugin: checking for updates from central

[INFO] artifact org.apache.maven.plugins:maven-compiler-plugin: checking for updates from central

[INFO] [clean:clean]

[INFO] Deleting directory C:\mavenWorkspace\aircore\target

[INFO] artifact org.apache.maven.plugins:maven-resources-plugin: checking for updates from central

[INFO] artifact org.apache.maven.plugins:maven-surefire-plugin: checking for updates from central

[INFO] artifact org.apache.maven.plugins:maven-jar-plugin: checking for updates from central

[INFO] artifact org.apache.maven.plugins:maven-install-plugin: checking for updates from central

[INFO] artifact org.apache.maven.plugins:maven-deploy-plugin: checking for updates from central

[INFO] [scm:update {execution: update}]

[INFO] Executing: svn --non-interactive update

[INFO] Working directory: C:\mavenWorkspace\aircore

[INFO] Storing revision in 'scm.revision' project property.

[INFO] [resources:resources]

[INFO] Using default encoding to copy filtered resources.

Downloading: http://repo1.maven.org/maven2/xmlenc/xmlenc/0.39/xmlenc-0.39.pom

[INFO] [compiler:compile]

 

 

If no deploy and only an install is done notice no scm:checkin (would be in bold)

 

- getInmasterDao().update

  - getInpartmasterDao().update

  - Setting Chgprog to InmasterPrimaryPartTest for this thread.

  - Setting Chgusername to invtestsuite for this thread.

  - original primary newRotPart=PP1204664170880

  - new primary newRotPart2=PP1204664170885

  @SLTests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.219 sec

 

Results :

 

Tests run: 207, Failures: 0, Errors: 0, Skipped: 0

 

[INFO] [jar:jar]

[INFO] Building jar: C:\mavenWorkspace\aircore\target\aircore-1.0-SNAPSHOT.jar

[INFO] [install:install]

[INFO] Installing C:\mavenWorkspace\aircore\target\aircore-1.0-SNAPSHOT.jar to C:\.m2\com\cms\aircore\1.0-SNAPSHOT\aircore-1.0-SNAPSHOT.jar

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESSFUL

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 1 minute 12 seconds

[INFO] Finished at: Tue Mar 04 12:56:12 PST 2008

[INFO] Final Memory: 13M/37M

[INFO] ------------------------------------------------------------------------

 

 

After deploy only notice scm:checkin (in bold below)

 

[INFO] [deploy:deploy]

altDeploymentRepository = null

[INFO] Retrieving previous build number from cms-internal

Uploading: scp://baksvr.cms:222/usr2/mav_root/internal/com/cms/aircore/1.0-SNAPSHOT/aircore-1.0-20080304.205950-935.jar

4/401K

401/401K

401K uploaded

[INFO] Retrieving previous metadata from cms-internal

[INFO] Uploading repository metadata for: 'snapshot com.cms:aircore:1.0-SNAPSHOT'

[INFO] Retrieving previous metadata from cms-internal

[INFO] Uploading project information for aircore 1.0-20080304.205950-935

[INFO] Retrieving previous metadata from cms-internal

[INFO] Uploading repository metadata for: 'artifact com.cms:aircore'

[INFO] [scm:checkin {execution: checkin}]

[INFO] Executing: svn --non-interactive commit --file C:\DOCUME~1\ROBERT~1\LOCALS~1\Temp\maven-scm-608012400.commit

[INFO] [eclipse:eclipse {execution: eclipse}]

[INFO] Using source status cache: C:\mavenWorkspace\stdcore\target\mvn-eclipse-cache.properties

[INFO] File C:\mavenWorkspace\stdcore\.project already exists. Additional settings will be preserved, run mvn eclipse:clean if you want old settings to be removed.

[INFO] Working directory: C:\mavenWorkspace\aircore

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESSFUL

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 1 minute 21 seconds

[INFO] Finished at: Tue Mar 04 13:00:00 PST 2008

[INFO] Final Memory: 13M/38M

[INFO] ------------------------------------------------------------------------

 

 

Outstanding Issues

 

1. update is running everytime (even during installs), I don’t know how to run it only if the deploy phases is later going to happen

2. the maven commit message is hardcoded in the pom.xml I would like a freaking popup to come up but I have no idea if that is possible or how this can be customized and I don’t want to lose the commit messages.

3. We are looking at how to keep developers from checking in with subclipse or tortoise svn so without running the tests. We are looking at subversion hooks for this to run the mvn tests on another machine besides the client if a certain string is not in the mvn checkin message.

 

Conclusions

I have ran into problems with developers checking in part their code to early and not all of it and no longer, or not doing updates before deploying.

 

This is awesome cause it keeps our developers from mvn deploying code that hasn’t been svn updated and checked in. And it also makes sure they have the most up to date svn code when they do a mvn deploy so they arent mvn deploying over other code.  

 

Hopefully we can get these outstanding issues worked out. If anyone has suggestions please let me know.

 



Re: Using the Maven SCM Plugin to integrate Maven2 and Subversion

Rob, I really found this interesting article very helpful. Unfortunately, the images are not showing up. It would be really great to see them. Thanks. -Joe

Re: Using the Maven SCM Plugin to integrate Maven2 and Subversion

I could only think of one image to add and that was my eclipse external tools configuration. I hope that was what you were looking for.

Add a comment Send a TrackBack