Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[MCOMPILER-478] testCompile with specific module-info.java partially copy target/classes to target/test-classes

Open
#689 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
build-system

Research direction

Start with the attached surefire-empty-packages.zip and reproduce the failure using Maven 3.8.4, Java 17, and mvn install. Inspect src/main/java/org/acme/impl/AImpl.java, the main and test module-info.java files, and the target/classes and target/test-classes outputs. Done means test compilation no longer leaves a partial module copy that breaks Surefire or maven-jar-plugin.

Written by the indexing model from the issue text.

Description

bug priority:major

Rocher Suchard opened MCOMPILER-478 and commented

Hello,

I am trying to understand how I can fix this particular bug that occurs while compiling test sources with src/test/java/module-info.java (or src/test/jpms/module-info.java in my case because this would make Eclipse fails, due to having two module-info.java).

The module-info that I put in src/test/jpms is more or less the same as {}src/main/jpms{}, but with some test modules (like {}org.opentest4j{}, {}org.junit.jupiter.api{}, and {}org.assertj.core{}). This is pretty much what is explained here at the end of page: https://maven.apache.org/surefire/maven-surefire-plugin/examples/jpms.html#.

When I try to run tests, maven-surefire-plugin fails: the JVM is not happy about a package not found.

1. Created at 2021-12-26T23:43:40.644
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'Error occurred during initialization of boot layer'.
1. Created at 2021-12-26T23:43:40.647
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'java.lang.module.FindException: Error reading module:'.
1. Created at 2021-12-26T23:43:40.647
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream '...\target\test-classes'.
1. Created at 2021-12-26T23:43:40.648
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'Caused by: java.lang.module.InvalidModuleDescriptorException:'.
1. Created at 2021-12-26T23:43:40.649
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 'Package org.acme.functions not found in module'.

At first, I thought it was something related to maven-surefire-plugin and I wanted to create a SUREFIRE JIRA issue, but I discovered that something - I presume maven-compiler-plugin - is copying used classes from target/classes to target/test-classes during test compilation.

In the case of my interface, it is not used and I presume the "something" that I speak about do partial copy of used files during compilation.

If we edit the src\main\java\org\acme\impl\AImpl.java to use the interface (should be commented in the attached ZIP):

public class AImpl implements A {

   @Override public void doSomethingCool() {
     org.acme.functions.BooleanConsumer bc = v -> {};
     throw new UnsupportedOperationException("no doing something cool");
   }
}

The class file is copied and surefire does not fail.

The attached ZIP file exhibit the problem :

If we simply compile with tests: {}mvn install{}: maven-surefire-plugin will fails to execute test because of missing package. I could probably remove the offending package from test/module-info but I don't think I should tinker to much : the test/module-info should really "extends" the main/module-info and only add packages/modules.

If we skip test : {}mvn install -DskipTests{}: maven-jar-plugin will fails to execute to process due to a jar error {}(jar: Package org.acme.functions missing from ModulePackages class file attribute{}){}.{}

A solution to both issues would be to create dedicated tests project, with its own module-info.java and another module name (eg: org.acme.tests) but that would no longer be a (modular) white box testing.

Note : the attached project requires Maven 3.8.4 (there is a maven wrapper inside) and Java 17. I don't know if this fail with Java 11.


Affects: 3.8.1

Attachments:

Dominant language
Java
Stars
261
Forks
194
Avg merge
1d 5h
Merged PRs (30d)
17

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-compiler-plugin

All issues in apache/maven-compiler-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.