Maven

This guide will walk you through setting up JRECC for a Maven project. This guide assumes that you already have set up a configuration file as described in the Setup section.

There are two parts to setting up JRECC for Maven, compilation and testing.

Compilation

First, create a new file, ./scripts/javac.sh, which will act as a simple proxy of the Java compiler. You can place this in the root of your project repository, or in a subdirectory within the root, for example, ./scripts/javac.sh. You will also need to mark this file as executable. <path to compiler.jar> is the path to the compiler JAR as listed on our website.

#!/usr/bin/env sh
java -jar "<path to compiler.jar>" "$@"

Next, we'll configure the maven-compiler-plugin to use this script in place of the default Java executable. Set executable to be the path of the javac.sh script. In order to use this executable, fork must also be set to true.

<!-- pom.xml -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <fork>true</fork>
        <executable>${maven.multiModuleProjectDirectory}/scripts/javac.sh</executable>
    </configuration>
</plugin>

We will also need to map the Maven repository artifacts into the remote execution sandbox. Add the following snippet to your project's JRECC configuration file.

directoryMappings:
  mavenRepository:
    local: ${env:HOME}/.m2/repository
    remote: /buildroot/maven/repository

In order for JARs to be built with consistent timestamps, you will need to set the project.build.outputTimestamp in the root POM.

<!-- pom.xml -->
<properties>
    <project.build.outputTimestamp>1980-01-01T00:00:02Z</project.build.outputTimestamp>
</properties>

For projects with more than one module, you also need to map the target directory for each module into the sandbox.

directoryMappings:
  mavenTarget:
    local: ./<module>/target
    remote: /buildroot/maven/<module>

Run mvn package -DskipTests to verify that your project builds successfully.

Testing

First, create a new file ./scripts/surefire/bin/java, which will act as a proxy for Surefire.

#!/usr/bin/env sh
/usr/bin/java -jar "<path to surefire.jar>" "$@"

Next, configure the maven-surefire-plugin to use this script in place of the default Java executable. Set jvm to the path of the script. You will also need to set the forkCount to 1.

<!-- pom.xml -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <forkCount>1</forkCount>
        <jvm>${maven.multiModuleProjectDirectory}/scripts/surefire/bin/java</jvm>
    </configuration>
</plugin>

We will also need to add the Surefire Facade JAR into the remote execution sandbox. Add the following snippet to your project's JRECC configuration file.

surefire:
  include:
    surefire-facade:
      path: # Path to surefire-facade.jar
      sandboxPath: /buildroot/surefire-facade.jar

Run mvn verify to build and test your project.