Maven tips and Tricks: Perforce (round 2)

In relation to my last post about maven and Perforce
this is a better solution that will work with both maven 1.0.x and 1.1.
The previous one doesn’t work under maven 1.1 because the bundled ant
version was updated to 1.6, that doesn’t include the optional perforce
tasks.

This time you’d need:

  • oro and ant-apache-oro as a dependency in your project.xml.
        <dependency>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
            <version>2.0.8</version>
            <!-- you don't need the root classloader if
                 only running under maven 1.1 -->
            <properties>
                <classloader>root</classloader>
            </properties>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant-apache-oro</artifactId>
            <version>1.6.4</version>
        </dependency>
  • The actual goal in maven.xml
        <!-- perforce -->
        <goal name="p4sync">
    
            <!--
                 you need Perforce command line client and maybe specify
                 P4CLIENT and P4PASSWD environment variables
            -->
    
            <ant:taskdef name="p4sync"
               classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Sync"
               classpathref="maven.dependency.classpath"/>
    
            <p4sync view="//depot/whatever/..." />
        </goal>

Another option to avoid defining each one of the tasks is creating a properties file in the classpath and load it with

        <ant:taskdef resource="com.whatever.PerforceTasks"
           classpathref="maven.dependency.classpath"/>

And the contents of the properties file is

        # Perforce tasks available
        p4change=org.apache.tools.ant.taskdefs.optional.perforce.P4Change
        p4delete=org.apache.tools.ant.taskdefs.optional.perforce.P4Delete
        p4label=org.apache.tools.ant.taskdefs.optional.perforce.P4Label
        p4labelsync=org.apache.tools.ant.taskdefs.optional.perforce.P4Labelsync
        p4have=org.apache.tools.ant.taskdefs.optional.perforce.P4Have
        p4sync=org.apache.tools.ant.taskdefs.optional.perforce.P4Sync
        p4edit=org.apache.tools.ant.taskdefs.optional.perforce.P4Edit
        p4integrate=org.apache.tools.ant.taskdefs.optional.perforce.P4Integrate
        p4resolve=org.apache.tools.ant.taskdefs.optional.perforce.P4Resolve
        p4submit=org.apache.tools.ant.taskdefs.optional.perforce.P4Submit
        p4counter=org.apache.tools.ant.taskdefs.optional.perforce.P4Counter
        p4revert=org.apache.tools.ant.taskdefs.optional.perforce.P4Revert
        p4reopen=org.apache.tools.ant.taskdefs.optional.perforce.P4Reopen
        p4fstat=org.apache.tools.ant.taskdefs.optional.perforce.P4Fstat

Note that you can’t use the properties file bundled with ant because it includes all optional tasks, wich would force you to include all ant-*.jar files in the classpath.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s