At the time of this writing, Maven has complete support for integrating with Subversion (SVN), Git, Concurrent Versions System (CVS), Bazzar, Jazz, Mercurial, Perforce, StarTeam, and CM Synergy. Support for Visual SourceSafe, Team Foundation Server, Rational ClearCase, and AccuRev is partially completed.
Let's try out a simple sample here, which integrates Maven with Subversion. You can download the complete sample from https://svn.wso2.org/repos/wso2/people/prabath/maven/chapter03/jose:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.packt</groupId> <artifactId>jose</artifactId> <version>1.0.0</version> <scm> <connection> scm:svn:https://svn.wso2.org/repos/wso2/people/prabath/maven/jose/src </connection> <developerConnection> scm:svn:https://svn.wso2.org/repos/wso2/people/prabath/maven/jose/src </developerConnection> <url> https://svn.wso2.org/repos/wso2/people/prabath/maven/jose </url> </scm> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId> <version>1.9</version> <configuration> <connectionType> connection </connectionType> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.nimbusds</groupId> <artifactId>nimbus-jose-jwt</artifactId> <version>2.26</version> </dependency> </dependencies> </project>
Here, we used a Maven SCM plugin to connect to Subversion. The plugin reads Subversion connection details from the <scm>
section at the top. The <scm>
configuration allows defining two types of connections: connection
and developerConnection
. The value of the connection
element should have read-only access to the source-controlling system while the value of the developerConnection
element should have read-write access. Most of the source-controlling systems let anyone check out the source code over plain HTTP while for commits or check-ins, it mandates the use of HTTPS. From the maven-scm-plugin
configuration, you can pick which type of connection you need by setting the value of the connectionType
element either to connection
or developerConnection
. If you are going to use the plugin only for read-only operations, then you should set the value of connectionType
to connection
. The value of the url
element under the SCM configuration should point to the browsable URL of the SCM.
According to the Subversion SCM plugin documentation available at http://maven.apache.org/scm/maven-scm-plugin/, it supports the following SCM goals:
scm:add
: This is the command to add filesscm:bootstrap
: This is the command to check out and build a projectscm:branch
: This is used to branch the projectscm:changelog
: This is the command to show the source code revisionsscm:check-local-modification
: This fails the build if there are any local modificationsscm:checkin
: This is the command to commit changesscm:checkout
: This is the command to get the source codescm:diff
: This is the command to show the differences between the working copy and the remote onescm:edit
: This is the command to start editing on the working copyscm:export
: This is the command to get a fresh exported copyscm:list
: This is the command to get the list of project filesscm:remove
: This is the command to mark a set of files for deletionscm:status
: This is the command to show the SCM status of the working copyscm:tag
: This is the command to tag a certain revisionscm:unedit
: This is the command to stop editing the working copyscm:update
: This is the command to update the working copy with the latest changesscm:update-subprojects
: This is the command to update all projects in a multi project buildscm:validate
: This validates the SCM information in the POM fileLet's a go through a few examples. The following command will check out the latest code before starting the build:
$ mvn scm:update clean install
The following command will find any local code modifications and will show the differences:
$ mvn scm:diff
Most of the source control systems (in fact all) protect the write operations with the username and password. In order to perform a write operation, we need to set up SVN credentials. There are two ways to do this. The first one is through the SCM plugin itself. Inside the SCM plugin configuration, we can define the SVN username and password as follows. In addition to this, the value of the connectionType
element must be set to developerConnection
:
<plugin> <groupId>org.apache.maven.plugins</groupId <artifactId>maven-scm-plugin</artifactId> <version>1.9</version> <configuration> <connectionType>developerConnection</connectionType> <username>username</username> <password>password</password> </configuration> </plugin>
The previous approach can lead to certain security issues. When you maintain your credentials in a POM file, these credentials cannot be encrypted. Also, you maintain your POM files in Subversion itself. In this case, the POM file with the credentials will be checked-in and any Subversion user can see your credentials.
The second approach is to set up the Subversion credentials via USER_HOME/.m2/settings.xml
. If you cannot find a settings.xml
file inside USER_HOME/.m2/
, you can copy the settings.xml
file from MAVEN_HOME/conf
. The id tag of the server configuration must point to the hostname of the Subversion connection URL. The configuration is as follows:
<server> <id>svn.wso2.org</id> <username>my_username</username> <password>my_password</password> </server>
The password in the previous configuration can be encrypted by following the approach defined in the Encrypting credentials in settings.xml section of this chapter.
The following command will check in the updated code after a successful build:
$ mvn clean install scm:checkin -Dmessage="updated source"
18.227.72.15