Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get maven surefire to run on classpath with module-info.java file present

I'm trying to write a library that can be run on the module path without trouble, but I'm using the org.testcontainers package for tests, and they have a number of dependencies that doesn't work on the module path.

These are the errors I get when trying to run surefire with my module-info.java present:

[WARNING] Can't extract module name from visible-assertions-2.1.1.jar: TtyCheck.class found in top-level directory (unnamed package not allowed in module) [WARNING] Can't extract module name from native-lib-loader-2.0.2.jar: native.lib.loader: Invalid module name: 'native' is not a Java identifier [WARNING] Can't extract module name from junixsocket-native-common-2.0.4.jar: junixsocket.native.common: Invalid module name: 'native' is not a Java identifier

These lead to further problems with class not found.

Note that this is a run time problem, the code compiles without problem and the produced jar works.

As far as I have understood the surefire documentation, it tries to run tests on the module path if the module-info.java file is present.

Is there any way to disable this behavior and fore maven surefire to run the tests on the class path instead of the module path?

like image 536
Alexander Kjäll Avatar asked Nov 16 '25 18:11

Alexander Kjäll


2 Answers

I resolved this by adding:

    <configuration>
      <forkCount>0</forkCount>
    </configuration>

To the maven-surefire-plugin plugin section, that gave me the warning [WARNING] useSystemClassloader setting has no effect when not forking.

like image 90
Alexander Kjäll Avatar answered Nov 18 '25 08:11

Alexander Kjäll


As of Surefire 3.0.0-M2, the correct solution is to set:

<configuration>
  <useModulePath>false</useModulePath>
</configuration>

See https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#useModulePath for more information.

like image 22
Gili Avatar answered Nov 18 '25 09:11

Gili