Search code examples
maven-3junit5maven-surefire-pluginjava-17maven-compiler-plugin

Error occurred during initialization of boot layer:Stream 'Caused by: java.lang.module.InvalidModuleDescriptorException: Package not found in module'


I have a project which I am now working on after having it laying around for some time using Java 17 and maven. During compiling the project I got the following error message:

[INFO] --- surefire:3.5.0:test (default-test) @ energy-meters ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Error occurred during initialization of boot layer
[ERROR] java.lang.module.FindException: Error reading module: C:\MyProject\target\test-classes
[INFO] Results:
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[WARNING] Corrupted channel by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file C:\MyProject\target\surefire-reports\2024-09-27T18-37-41_721-jvmRun1.dumpstream

Within the mentioned file there are the following messages:

Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'Error occurred during initialization of boot layer'.
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'java.lang.module.FindException: Error reading module: C:\Users\PowerStat\Documents\EnergyMeters\target\test-classes'.
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'Caused by: java.lang.module.InvalidModuleDescriptorException: Package de.powerstat.energymeters.entities not found in module'.

My project structure is as follows:

src/main/java/
  de/powerstat/energymeters/
    entities/
      MeterReader.java
    values/
      *.java
  module-info.java
src/test/java/
  de/powerstat/energymeters/
    entities/test/
      MeterReaderTests.java
    values/test/
      *.java
  module-info.java

My test module-info.java file looks as follows:

open module de.powerstat.energymeters
 {
  exports de.powerstat.energymeters.entities;
  exports de.powerstat.energymeters.values;
  requires transitive de.powerstat.validation;
  requires org.apache.logging.log4j;
  requires com.github.spotbugs.annotations;
  requires org.junit.jupiter.api;
  requires org.junit.platform.launcher;
  requires org.junit.platform.suite.api;
  requires org.junit.jupiter.params;
 }

After some time I found that the problem seems not to be in the context of the surefire plugin, but within the compiler plugin, because there I have the following output when using -X:

[INFO]  New dependency detected: C:\Users\PowerStat\Documents\EnergyMeters\target\classes\de\powerstat\energymeters\entities\MeterReader.class

And exactly this package/class is missing within the C:\MyProject\target\test-classes\de\powerstat\energymeters\entities\ directory - only the test class can be found within the test/ subdirectory.

So my question is: What is the reason for this error message?


Solution

  • After some digging and thinking I found the Problem:

    It looks like I have not finished to writing a test for the MeterReader class before I let my project laying around. So the JUnit test was only a skeleton:

    package de.powerstat.energymeters.entities.test;
    
    final class MeterReaderTests
     {
      MeterReaderTests()
       {
        super();
       }
     }
    

    Without having the MeterReader class as dependency within it.

    After adding the dependency and a rudimentary test, compiling works fine again:

    package de.powerstat.energymeters.entities.test;
    
    import static org.junit.jupiter.api.Assertions.assertNotNull;
    import org.junit.jupiter.api.Test;
    import de.powerstat.energymeters.entities.MeterReader;
    
    final class MeterReaderTests
     {
      MeterReaderTests()
       {
        super();
       }
    
      @Test
      void testMeterReaderOk()
       {
        final MeterReader cleanMeterReader = MeterReader.of();
        assertNotNull(cleanMeterReader, "MeterReader not as expected");
       }
     }