Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 77 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
<invoker.parallelThreads>1C</invoker.parallelThreads>
<project.build.outputTimestamp>2025-10-05T19:10:54Z</project.build.outputTimestamp>
<maven-toolchains-plugin.version>3.2.0</maven-toolchains-plugin.version>

<mojo.java.target>8</mojo.java.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -287,24 +289,13 @@
<configuration>
<proc>none</proc>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<parameters>true</parameters>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
Expand Down Expand Up @@ -374,6 +365,80 @@
</build>

<profiles>
<profile>
<!-- Multi-Release JAR: Compile Java 9+ specific code when JDK 9+ is available -->
<id>java9-mrjar</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Compile Java 9+ specific code -->
<execution>
<id>java9-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
</configuration>
</execution>
<!-- Test compilation with parameters enabled -->
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<source>9</source>
<target>9</target>
<parameters>true</parameters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- JDK 8: Use simplified test compilation -->
<id>java8-tests</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<source>8</source>
<target>8</target>
<parameters>true</parameters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- workaround for concurrent access to local repository on Windows -->
<!-- https://issues.apache.org/jira/browse/MRESOLVER-372 -->
Expand Down
49 changes: 49 additions & 0 deletions src/it/projects/mexec-gh-426/consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>java_module-serviceloader</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>consumer</artifactId>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>contract</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>provider</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<mainClass>consumer/org.example.consumer.App</mainClass>
</configuration>
<executions>
<execution>
<id>test-jpms-serviceloader</id>
<phase>integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module consumer {
requires contract;
uses org.example.api.Greeter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example.consumer;

import java.util.ServiceLoader;
import org.example.api.Greeter;

public class App {
public static void main(String[] args) {
ServiceLoader<Greeter> loader = ServiceLoader.load(Greeter.class);

Greeter greeter = loader.findFirst()
.orElseThrow(() -> new RuntimeException("No Greeter service provider found"));

String message = greeter.greet("World");
System.out.println(message);
}
}
13 changes: 13 additions & 0 deletions src/it/projects/mexec-gh-426/contract/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>java_module-serviceloader</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>contract</artifactId>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module contract {
exports org.example.api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.example.api;

public interface Greeter {
String greet(String name);
}
3 changes: 3 additions & 0 deletions src/it/projects/mexec-gh-426/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals = clean install
invoker.java.version = 11+
invoker.buildResult = success
37 changes: 37 additions & 0 deletions src/it/projects/mexec-gh-426/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>java_module-serviceloader</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>JPMS ServiceLoader Test</name>
<description>Test exec:java with Java Module System and ServiceLoader</description>

<modules>
<module>contract</module>
<module>provider</module>
<module>consumer</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
21 changes: 21 additions & 0 deletions src/it/projects/mexec-gh-426/provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>java_module-serviceloader</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>provider</artifactId>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>contract</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module provider {
requires contract;
exports org.example.provider;
provides org.example.api.Greeter with org.example.provider.GreeterImpl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.provider;

import org.example.api.Greeter;

public class GreeterImpl implements Greeter {
public String greet(String name) {
return "Hello from ServiceLoader, " + name + "!";
}
}
36 changes: 36 additions & 0 deletions src/it/projects/mexec-gh-426/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Verify that the build log contains the expected output from ServiceLoader
File buildLog = new File(basedir, 'build.log')
assert buildLog.exists()

String log = buildLog.getText('UTF-8')

// Check that exec:java ran successfully
assert log.contains('[INFO] --- exec')
assert log.contains(':java')

// Check that ServiceLoader found the provider and printed the greeting
assert log.contains('Hello from ServiceLoader, World!')

// Ensure no errors about missing service providers
assert !log.contains('No Greeter service provider found')

println "SUCCESS: JPMS ServiceLoader test passed - provider was loaded and executed correctly"
Loading