Using the Maven SCM plugin

Maven provides a mechanism to interact with SCM systems in a vendor-independent way. Typically, a Maven project is checked in an SCM. Using the Maven SCM plugin, you can perform a number of SCM-related activities.

Getting ready

The Maven project that we want to use the plugin with should be in an SCM. Maven supports a number of SCM providers. We will use Git to illustrate this.

How to do it...

  1. Add the following code to your pom file:
      <scm>
            <connection>scm:git:https://bitbucket.org/maruhgar/apache-maven-cookbook</connection>
         <developerConnection>scm:git:https://[email protected]/maruhgar/apache-maven-cookbook</developerConnection>
            <url>https://bitbucket.org/maruhgar/apache-maven-cookbook</url>
        </scm>
  2. Run the following command:
    mvn scm:status
    
  3. Observe the output in Windows:
    How to do it...
  4. For Linux, the output will be as follows:
    How to do it...

How it works...

When the status goal of the Maven SCM plugin is run, it uses the information in the scm tag of the pom file to get the SCM details. It uses this information and invokes the corresponding scm command to get the status information. In the preceding example, it is the git status.

Tip

The command-line version of the relevant SCM client must be installed and available in the Maven path for this to work.

There are three entries in the scm tag:

  • connection: This is the connection information to access the repository. This is typically in the following form:
    <service name>:<scm implementation>:<repository url>
    • service name: This would be an SCM
    • scm implementation: This would be one of the supported SCMs
    • repository url: This would be a URL for the repository
  • developerConnection: This is similar to any connection, except that this may need authentication or have additional privileges. Typically, the connection access would be read-only, while the developerConnection access would be read-write.
  • url: This is the repository URL.

You will also notice that the appropriate shell command is used based on the operating system, which is cmd.exe in the case of Windows and sh in the case of Linux.

There's more...

The Maven SCM plugin provides a number of other commands for various SCM operations, such as add, remove, checkin, checkout, update, diff, branch, and tag.

Bootstrap is an interesting option to checkout and build a project with:

  1. Create a new Maven project (or open the bootstrap-project file).
  2. Add a valid Maven project in the scm section:
    <scm>
        <connection>scm:git:https://github.com/maruhgar/mvn-examples</connection>
        <url>https://github.com/maruhgar/mvn-examples</url>
      </scm>
  3. Add the following entries in the build section:
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.9.2</version>
          <configuration>
            <goals>install</goals>
            <goalsDirectory>test-properties</goalsDirectory>
          </configuration>
        </plugin>
      </plugins>
    </build>
  4. Run the Maven command:
    mvn scm:bootstrap
    
  5. Observe the results:
    There's more...

Our Maven project has checked another Maven project, using the information in the scm section, and run the specified goal on this. We specify a goalsDirectory element because the SCM contains a number of projects and we want to execute the goals for a specific project, in this case test-properties.

..................Content has been hidden....................

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