[ 
https://issues.apache.org/jira/browse/MCOMPILER-478?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Rocher Suchard updated MCOMPILER-478:
-------------------------------------
    Description: 
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.
{code:java}
# 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'.
# 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:'.
# Created at 2021-12-26T23:43:40.647
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 
'...\target\test-classes'.
# 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:'.
# 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'.
{code}
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):
{code:java}
public class AImpl implements A {

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

  was:
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.
{code:java}
# 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'.
# 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:'.
# Created at 2021-12-26T23:43:40.647
Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 
'...\target\test-classes'.
# 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:'.
# 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'.
{code}
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):
{code:java}
public class AImpl implements A {

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

*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.


> testCompile with specific module-info.java partially copy target/classes to 
> target/test-classes
> -----------------------------------------------------------------------------------------------
>
>                 Key: MCOMPILER-478
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-478
>             Project: Maven Compiler Plugin
>          Issue Type: Bug
>    Affects Versions: 3.8.1
>            Reporter: Rocher Suchard
>            Priority: Major
>         Attachments: surefire-empty-packages.zip
>
>
> 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.
> {code:java}
> # 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'.
> # 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:'.
> # Created at 2021-12-26T23:43:40.647
> Corrupted STDOUT by directly writing to native stream in forked JVM 1. Stream 
> '...\target\test-classes'.
> # 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:'.
> # 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'.
> {code}
> 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):
> {code:java}
> public class AImpl implements A {
>    @Override public void doSomethingCool() {
>      org.acme.functions.BooleanConsumer bc = v -> {};
>      throw new UnsupportedOperationException("no doing something cool");
>    }
> }
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to