Search code examples
maven-2mercurialmaven-pluginmaven-scm

How can I configure Maven to commit to a Mercurial repository when I install:install


Maven's SCM plug-in doesn't appear to provide a "commit" goal. scm:checkin performs a commit AND push. I need to avoid the push.

I'm simply interested in doing an hg commit during install:install. I'm not using the release plugin and don't need it yet. I'm simply working locally in a multi-module environment and want to ensure that my source repository aligns with my Maven locally-installed snapshots for each module. In other words, every time I install a new snapshot of a module, I want the related code committed to hg to make every snapshot directly correlate to an hg revision (or range of revisions when multiple commits occur between snapshots).


Solution

  • The following will bind scm:checkin to the install phase. As long as the repository is a file:// scheme (at least for Mercurial, according to the code), a push is not performed during scm:checkin.

    1. Define properties used in the following steps:

      <properties>
        <message>maven install:install auto-checkin.</message>
        <repository.local>file:///path/to/local/repository</repository.local>
        <repository.type>hg</repository.type>
      </properties>
      

      The <message> can be anything you choose. It isn't ideal to be completely fixed as commits should include meaningful messages as to what changes were made. But, I do believe there should be a standard message included in auto-commits to identify it as such. Just modify the <message> property from step 1. before each install.

    2. This is just a standard scm node for a Maven-based project. Since this is concerned only with a local repository, the URLs are all the same.

      <scm>
        <connection>scm:${repository.type}:${repository.local}</connection>
        <developerConnection>scm:${repository.type}:${repository.local}</developerConnection>
        <url>scm:${repository.type}:${repository.local}</url>
      </scm>
      
    3. This is plug-in that runs during the install phase that performs the commit. It'll simply execute the proper scm checkin based on the definition in step 2.

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <phase>install</phase>
                <goals>
                  <goal>checkin</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      

    One problem is that I receive the following.

    DEPRECATED: Binding aggregator mojos to lifecycle phases in the POM is considered dangerous. This feature has been deprecated. Please adjust your POM files accordingly.

    I'm looking into how to resolve it but, for now, it works and I'm going with it.