Fork me on GitHub

Communication Channels used between the Maven Process and Surefire Process

There is one way to change the communication channel and two types of connection in the Surefire. The communication channel can be changed even by the user in the user's POM. The physical layer of the channel can be switched from Process Pipes to TCP/IP. The user select the default implementations in the POM or the user can implement his own channel without asking the Apache Maven development team for providing a new support. Let's show you how this can be accomplished.

forkNode

The configuration is done by using only one configuration parameter forkNode.

The TCP/IP communication channel

The Surefire plugin uses process pipes by default. The implementation class for default configuration is org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory and it does not have to be specified. The TCP/IP channel can be selected as follows and the implementation class has to be specified:

<project>
    [...]
    <build>
        <plugins>
            [...]
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
                <configuration>
                    <forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
                </configuration>
            </plugin>
            [...]
        </plugins>
    </build>
    [...]
</project>

Custom implementation

The custom implementation involves two implementations. The first is used by the Maven process and there you should implement the interface org.apache.maven.surefire.extensions.ForkNodeFactory, use the implementation in a dependency your-extension-api-impl-artifactid declared below the plugin and configuration should specify fully qualified class name of your custom ForkNodeFactory in the attribute implementation.

The second implementation is SPI which is utilized by the forked JVM. Implement the Java SPI interface org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory in the artifact your-extension-spi-impl-artifactid.

<project>
    [...]
    <dependencies>
        <dependency>
            <groupId>your-extension-spi-impl-groupid</groupId>
            <artifactId>your-extension-spi-impl-artifactid</artifactId>
            <version>your-extension-spi-impl-version</version>
        </dependency>
    </dependencies>
    [...]
    <build>
        <plugins>
            [...]
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
                <dependencies>
                    <dependency>
                        <groupId>your-extension-api-impl-groupid</groupId>
                        <artifactId>your-extension-api-impl-artifactid</artifactId>
                        <version>your-extension-api-impl-version</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <forkNode implementation="your.extention.api.impl.CustomForkNodeFactory"/>
                </configuration>
            </plugin>
            [...]
        </plugins>
    </build>
    [...]
</project>

The project your-extension-api-impl-artifactid should have the following dependency as mandatory:

<project>
    [...]
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>surefire-extensions-api</artifactId>
            <version>3.2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    [...]
</project>

The project your-extension-spi-impl-artifactid should have the following dependency as mandatory:

<project>
    [...]
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>surefire-extensions-spi</artifactId>
            <version>3.2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    [...]
</project>

Your SPI implementation appears in src/main/resources/META-INF/services/org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory and contains one implementation class. Your POM already specified it, see your.extention.api.impl.CustomForkNodeFactory.