Simone Bordet created SUREFIRE-1667:
---------------------------------------

             Summary: Crash with JPMS "requires static"
                 Key: SUREFIRE-1667
                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1667
             Project: Maven Surefire
          Issue Type: Bug
    Affects Versions: 3.0.0-M3
            Reporter: Simone Bordet
         Attachments: surefire-jpms-issue.tgz

The attached project has JPMS modules where:
{{moduleA}} requires {{moduleB}}
{{moduleB}} requires static {{moduleC}}.
Furthermore, {{moduleA}} tests require {{moduleC}}.

Running the attached project ends up with the following test failure:

{code}
[ERROR] test(org.cometd.a.ATest) Time elapsed: 0.01 s <<< ERROR!
java.lang.NoClassDefFoundError: org/cometd/c/C
 at [email protected]/org.cometd.a.ATest.test(ATest.java:15)
{code}

The reason is that {{plexus-java}} creates a wrong module-path and class-path 
because it does not take into account the {{static}} modified in the JPMS 
directive {{requires static <module>}}.

For the attached project, running {{moduleA}} tests generates this (simplified):

{code}
--module-path
moduleA/target/classes:
moduleB-1.0.0-SNAPSHOT.jar:
moduleC-1.0.0-SNAPSHOT.jar

--class-path
surefire-booter-3.0.0-M3.jar:
surefire-api-3.0.0-M3.jar:
surefire-logger-api-3.0.0-M3.jar:
junit-4.12.jar:
hamcrest-core-1.3.jar:
surefire-junit4-3.0.0-M3.jar:
common-java5-3.0.0-M3.jar:
common-junit3-3.0.0-M3.jar:
common-junit4-3.0.0-M3.jar"

--patch-module
moduleA=moduleA/target/test-classes

--add-exports
moduleA/org.cometd.a=ALL-UNNAMED

--add-modules
moduleA

--add-reads
moduleA=ALL-UNNAMED
{code}

However, {{moduleC}} should be in the class-path, not in the module-path, as it 
is only required for testing.

It is in the module-path because it is pulled in as a transitive dependency 
from {{moduleB}}, without taking into account that it is a {{requires static}}.

Correct behavior should be IMHO that {{moduleC}} is not in the module-path but 
rather in the class-path, respecting the semantic of JPMS {{requires static}}.

The workaround is to configure the Maven Surefire Plugin with {{--add-module 
moduleC}}, but that is incorrect.

The relevant {{plexus-languages/plexus-java}} code that builds the module-path 
and the class-path is in {{LocationManager.resolvePaths()}}. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to