cowwoc opened a new issue, #3521:
URL: https://github.com/apache/maven-surefire/issues/3521

   ### Affected version
   
   3.6.0
   
   ### Bug description
   
   When a project with a test module descriptor 
(`src/test/java/module-info.java`) runs TestNG tests, Surefire 3.6.0 runs them 
through the JUnit Platform provider (`TestNG is present. Adding per default 
org.junit.support:testng-engine:1.1.0`). The forked JVM then prints:
   
   ```
   WARNING: Unknown module: org.junit.platform.commons specified to --add-opens
   WARNING: Unknown module: org.junit.platform.commons specified to --add-opens
   ```
   
   The tests pass, but the warnings appear in every run. Surefire 3.5.5 runs 
the same project without them.
   
   **Cause**
   
   `AbstractSurefireMojo$JUnitPlatformProviderInfo` adds these arguments:
   
   ```
   --add-opens 
org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
   --add-opens 
org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
   ```
   
   However, `junit-platform-commons` is placed on the class path rather than 
the module path, so the JVM has no module named `org.junit.platform.commons`. 
The args file from `-X` (abridged):
   
   ```
   --module-path
   
"<project>/target/test-classes:<project>/target/classes:…/testng-7.12.0.jar:…/slf4j-api-2.0.16.jar:…/jcommander-1.83.jar:…/jquery-3.7.1.jar"
   --class-path
   
"…/surefire-booter-3.6.0.jar:…/surefire-junit-platform-3.6.0.jar:…/junit-platform-engine-1.14.4.jar:…/junit-platform-launcher-1.14.4.jar:…/junit-platform-commons-1.14.4.jar:…/testng-engine-1.1.0.jar:…"
   --add-modules
   ALL-MODULE-PATH
   --add-opens
   org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
   --add-opens
   org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
   org.apache.maven.surefire.booter.ForkedBooter
   ```
   
   The `--add-opens` arguments should only be added when 
`org.junit.platform.commons` is resolved as a named module, i.e. when it is on 
the module path.
   
   **Reproducer**
   
   `pom.xml`:
   
   ```xml
   <project xmlns="http://maven.apache.org/POM/4.0.0";>
        <modelVersion>4.0.0</modelVersion>
        <groupId>demo</groupId>
        <artifactId>surefire-add-opens</artifactId>
        <version>1.0-SNAPSHOT</version>
        <properties>
                <maven.compiler.release>27</maven.compiler.release>
                
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        <dependencies>
                <dependency>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                        <version>7.12.0</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
        <build>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.16.0</version>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>3.6.0</version>
                        </plugin>
                </plugins>
        </build>
   </project>
   ```
   
   `src/main/java/module-info.java`:
   
   ```java
   module demo
   {
        exports demo;
   }
   ```
   
   `src/main/java/demo/Greeter.java`:
   
   ```java
   package demo;
   
   public final class Greeter
   {
        public String greet()
        {
                return "hello";
        }
   }
   ```
   
   `src/test/java/module-info.java`:
   
   ```java
   module demo.test
   {
        requires demo;
        requires org.testng;
   
        exports demo.test to org.testng;
   }
   ```
   
   `src/test/java/demo/test/GreeterTest.java`:
   
   ```java
   package demo.test;
   
   import demo.Greeter;
   import org.testng.annotations.Test;
   
   import static org.testng.Assert.assertEquals;
   
   public final class GreeterTest
   {
        @Test
        public void greets()
        {
                assertEquals(new Greeter().greet(), "hello");
        }
   }
   ```
   
   Run `mvn test`.
   
   | Setup | Result |
   |---|---|
   | Surefire 3.6.0, with `src/test/java/module-info.java` | Two `Unknown 
module` warnings |
   | Surefire 3.6.0, without `src/test/java/module-info.java` | No warning |
   | Surefire 3.5.5, with `src/test/java/module-info.java` | No warning |
   
   **Environment**
   
   - Maven 3.10.0
   - Java 27 (Zulu 27.0.0+35)
   - Linux
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to