Source Control Management systems

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.

Maven with Subversion

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 files
  • scm:bootstrap: This is the command to check out and build a project
  • scm:branch: This is used to branch the project
  • scm:changelog: This is the command to show the source code revisions
  • scm:check-local-modification: This fails the build if there are any local modifications
  • scm:checkin: This is the command to commit changes
  • scm:checkout: This is the command to get the source code
  • scm:diff: This is the command to show the differences between the working copy and the remote one
  • scm:edit: This is the command to start editing on the working copy
  • scm:export: This is the command to get a fresh exported copy
  • scm:list: This is the command to get the list of project files
  • scm:remove: This is the command to mark a set of files for deletion
  • scm:status: This is the command to show the SCM status of the working copy
  • scm:tag: This is the command to tag a certain revision
  • scm:unedit: This is the command to stop editing the working copy
  • scm:update: This is the command to update the working copy with the latest changes
  • scm:update-subprojects: This is the command to update all projects in a multi project build
  • scm:validate: This validates the SCM information in the POM file

Let'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>

Tip

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"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.72.15