I am migrating a project to Maven and as we were used to always reference our builds by the latest change number in our Perforce SCM repository, I would like to be able to extract this information
I am trying to configure Maven scm plugin via following resources:
First I don't understand how to make it work, so if anybody has a fully working example, I will be happy to, on my side I have tried by adding in my pom:
<scm>
<connection>
scm:perforce:localhost:1666://depot/
<my_project>
/
<version>
</connection>
<developerConnection>
scm:perforce:localhost:1666:/depot/
<my_project>
/
<version>
</developerConnection>
<url>http://somerepository.com/view.cvs</url>
</scm>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.6</version>
<dependencies>
<!-- P4Maven -->
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4maven</artifactId>
<version>[2011,2012)</version>
</dependency>
</dependencies>
<configuration>
<connectionType>//depot/proto/kernel/kernel/04.00/maven2</connectionType>
<username>my local username</username>
<password>xxxxxx</password>
<includes>**</includes>
</configuration>
</plugin>
</plugins>
this is leading me to:
[INFO] --- maven-scm-plugin:1.6:checkout (default-cli) @ kernel ---
mars 27, 2012 9:54:08 AM org.sonatype.guice.bean.reflect.Logs$JULSink warn
Avertissement: Error injecting: org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider
java.lang.NoClassDefFoundError: org/apache/maven/scm/command/info/InfoScmResult
Surely forgot something, I will try to read again the instructions and see what I miss, but if anybody knows ...
Anyway, my question is rather: is it worth trying it ? I don't see in the available actions from scm plugin anything that will help me getting the last change information and integrate it into a reference build number. Shall I develop my own plugin for this ?
Thanks in advance.
Maven SCM supports Maven plugins (for example maven-release-plugin) and other tools by providing them with a common API for source code management operations. You can look at the list of SCMs for more information on using Maven SCM with your favorite SCM tool.
This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. Releasing a project is made in two steps: prepare and perform. Note: Maven 3 users are encouraged to use at least Maven-3.0.
I got some advice from one of the P4Maven developers that might help.
First, check your configuration. The "..." in the "" tag should be one of the tag names in the "" tag (i.e. "connection" or "developerConnection")
There two options to use Maven with Perforce SCM.
Use the default (built-in) Maven Perforce SCM provider (p4 commandline based)
[environment variables] P4CLIENT= P4USER= P4PASSWD=
or
[JVM args] -Dusername= -Dpassword=
[pom.xml] ...
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.4</version>
</plugin>
...
...
<!-- SCM Settings -->
<scm>
<connection>scmerforce:localhost:1666://depot/someproject</connection>
<developerConnection>scmerforce:localhost:1666://depot/someproject</developerConnection>
<url>scmerforce://depot/simple</url>
</scm>
...
[pom.xml]
...
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.4</version>
<dependencies>
<!-- P4Maven -->
<dependency>
<groupId>com.perforce</groupId>
<artifactId>p4maven</artifactId>
<version>[2011,2012)</version>
</dependency>
</dependencies>
<configuration>
<connectionType>connection</connectionType>
<username>someuser</username>
<password>somepassword</password>
<includes>**</includes>
</configuration>
</plugin>
...
...
scm4:localhost:1666://depot/someproject scm4:localhost:1666://depot/someproject scm4://depot/someproject
...
Note that for P4Maven we're overriding the default provider inside the "maven-scm-plugin" plugin.
Note that we're using "scmp4" (if using P4Maven) instead of "scmperforce" (built-in default) as the provider name, since "perforce" is taken by the existing default implementation.
I was struggling with exactly the same problem recently - I just wanted to get a Perforce revision number to use it in maven artifacts (for example as a part of a name). I checked buildnumber-maven-plugin, but it does not support Perforce at all. I also tried maven-release-plugin, but it seems to me as it does too much and I even didn't find out if it will do what I need.
Anyway I ended up with a solution which I don't like, but it works. I get this revision number directly with p4 executable via ant and antrun plugin (you must use the latest 1.7 version to export ant property to maven). You also need to have p4 executable available.
After this plugin configuration is used you have ${revision.number} available in maven.
<!-- Get Perforce latest change number -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
</dependencies>
<configuration>
<exportAntProperties>true</exportAntProperties>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="maven.plugin.classpath"/>
<!-- Login to p4 -->
<exec executable="p4" inputstring="${p4.password}">
<arg value="-p${p4.server}"/>
<arg value="-c${p4.client}"/>
<arg value="-u${p4.username}"/>
<arg value="login"/>
</exec>
<!-- Get reivision description text -->
<exec executable="p4" outputproperty="revision.description">
<arg value="-p${p4.server}"/>
<arg value="-c${p4.client}"/>
<arg value="-u${p4.username}"/>
<arg value="changes"/>
<arg value="-m1"/>
<arg value="//...#have"/>
</exec>
<!-- Logout from p4 -->
<exec executable="p4">
<arg value="-p${p4.server}"/>
<arg value="-c${p4.client}"/>
<arg value="-u${p4.username}"/>
<arg value="logout"/>
</exec>
<!-- Parse revision description to retrieve only revision number -->
<propertyregex property="revision.number"
input="${revision.description}"
regexp="Change ([0-9]*) on ([a-z,0-9]*)"
select="\1"
casesensitive="false"/>
<echo>Perforce latest revision number: ${revision.number}</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With