Skip to content

[MCOMPILER-481] JPMS Regression: cannot access <class> (requires static module not include anymore) #712

Closed

Description

@jira-importer

Simone Bordet opened MCOMPILER-481 and commented

Version 3.8.1 is not affected.

The problem lies in how the module-path is constructed by the maven-compiler-plugin – not sure what changes from 3.8.1 caused this.

In 3.8.1:

-d
  /home/simon/tmp/compiler-bug/app/target/test-classes
-classpath
  /home/simon/tmp/compiler-bug/app/target/test-classes
  /home/simon/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.8.2/junit-jupiter-api-5.8.2.jar
  /home/simon/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar
  /home/simon/.m2/repository/org/junit/platform/junit-platform-commons/1.8.2/junit-platform-commons-1.8.2.jar
  /home/simon/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
  
--module-path
  /home/simon/tmp/compiler-bug/app/target/classes
  /home/simon/.m2/repository/org/example/compiler-bug-service/1.0-SNAPSHOT/compiler-bug-service-1.0-SNAPSHOT.jar
  /home/simon/.m2/repository/org/eclipse/jetty/jetty-util-ajax/10.0.7/jetty-util-ajax-10.0.7.jar
  /home/simon/.m2/repository/org/eclipse/jetty/jetty-util/10.0.7/jetty-util-10.0.7.jar
  /home/simon/.m2/repository/org/slf4j/slf4j-api/2.0.0-alpha5/slf4j-api-2.0.0-alpha5.jar
  
-sourcepath
  /home/simon/tmp/compiler-bug/app/src/test/java
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
  
-s
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
-g
-nowarn
--release
  11
-encoding
  UTF-8
--patch-module
  compiler.bug.app=/home/simon/tmp/compiler-bug/app/target/classes
  /home/simon/tmp/compiler-bug/app/src/test/java
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
  
--add-reads
  compiler.bug.app=ALL-UNNAMED 

In 3.9.0:

-d
  /home/simon/tmp/compiler-bug/app/target/test-classes
-classpath
  /home/simon/tmp/compiler-bug/app/target/test-classes
  /home/simon/.m2/repository/org/eclipse/jetty/jetty-util-ajax/10.0.7/jetty-util-ajax-10.0.7.jar
  /home/simon/.m2/repository/org/eclipse/jetty/jetty-util/10.0.7/jetty-util-10.0.7.jar
  /home/simon/.m2/repository/org/slf4j/slf4j-api/2.0.0-alpha5/slf4j-api-2.0.0-alpha5.jar
  /home/simon/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.8.2/junit-jupiter-api-5.8.2.jar
  /home/simon/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar
  /home/simon/.m2/repository/org/junit/platform/junit-platform-commons/1.8.2/junit-platform-commons-1.8.2.jar
  /home/simon/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
  
--module-path
  /home/simon/tmp/compiler-bug/app/target/classes
  /home/simon/.m2/repository/org/example/compiler-bug-service/1.0-SNAPSHOT/compiler-bug-service-1.0-SNAPSHOT.jar
  
-sourcepath
  /home/simon/tmp/compiler-bug/app/src/test/java
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
  
-s
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
-g
-nowarn
--release
  11
-encoding
  UTF-8
--patch-module
  compiler.bug.app=/home/simon/tmp/compiler-bug/app/target/classes
  /home/simon/tmp/compiler-bug/app/src/test/java
  /home/simon/tmp/compiler-bug/app/target/generated-test-sources/test-annotations
  
--add-reads
  compiler.bug.app=ALL-UNNAMED 

Running with 3.9.0 yields:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.9.0:testCompile (default-testCompile) on project compiler-bug-app: Compilation failure
[ERROR] /home/simon/tmp/compiler-bug/app/src/test/java/org/test/app/MainTest.java:[12,38] cannot access org.eclipse.jetty.util.ajax.JSON
[ERROR]   class file for org.eclipse.jetty.util.ajax.JSON not found 

Class JSON is in {}jetty-util-10.0.7.jar{}.

In 3.9.0 this jar is missing from the module-path, causing the error.

Attached you can find a reproducer: switch the maven-compiler-plugin version from 3.8.1 (works) to 3.9.0 (does not work) in the main POM.


Affects: 3.9.0

Attachments:

Issue Links:

Remote Links:

1 votes, 8 watchers

Activity

  1. jira-importer commented on Jan 17, 2022

    @jira-importer
    Author

    Simone Bordet commented

    The setup is that module "app" depends on module "service".

    Module "service" has an interface and a default implementation that depends optionally (requires static) on the JSON class (present in the jetty-util-ajax-10.0.7.jar).

    Module "app" wants to perform some test, so it has to bind to an implementation (only for the tests – the source still depends only on the interface declared in module "service").

    I would have expected that putting jetty-util-ajax-10.0.7.jar in the classpath with --patch-module and --add-reads compiler.bug.app=ALL-UNNAMED would be enough, but apparently it is not, so this may well be a javac compiler bug?

    The only alternative I see is to keep track of requires static dependencies, and if a Maven module declares them as a dependency in the POM, then they get added to the module-path?

    Robert Scholte, Olivier Lamy, Christian Stein any idea?

    Thanks!

  2. jira-importer commented on Jan 17, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Thanks for test-project, that really helps to understand the issue. The handling of static required modules has changed a bit. I need some time to figure out how we want to handle an optional dependencies in this way.

  3. jira-importer commented on Jan 18, 2022

    @jira-importer
    Author

    Simone Bordet commented

    The more I think about this, the more I'm surprised at why --add-reads compiler.bug.app=ALL-UNNAMED is not enough...

  4. jira-importer commented on Jan 19, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    requires static are not include anymore per default (ResolvePathsRequest has includeStatic field false per default).

    BTW I tried to change m-compiler-p to ResolvePathsRequest.setIncludeStatic(true) but doesn't work.

    Robert Scholte  This commit has some issues codehaus-plexus/plexus-languages@868b3d7 I'm investigating.

    Simone Bordet not sure why you need static

    requires static org.eclipse.jetty.util.ajax;

    Thanks for the test project. As there is no license included do you mind if I include it as a test in the maven-compiler-plugin code?

     

     

  5. jira-importer commented on Jan 19, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Based on the test, it is about supporting "static transitive", which is very unusual but valid. I should have added a cross-link to the original issue in one of the plugins.

  6. jira-importer commented on Jan 19, 2022

    @jira-importer
    Author

    Robert Scholte commented

    ResolvePathsRequest.setIncludeStatic(true) did fix it for me, still wondering if this is the right approach.

  7. jira-importer commented on Jan 19, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Found it, it was MJAVADOC-677 that required this change.

  8. jira-importer commented on Jan 20, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    Robert Scholte  I started a branch called MCOMPILER-481-requires-static-included draft PR #82

    This PR include the sample project as a new IT test.

    simple change ResolvePathsRequest.setIncludeStatic(true) do not fix the problem

    I made some other changes in plexus-java see draft PR codehaus-plexus/plexus-languages#106 the changes fix this problem but there is now 2 test failures

    still investigating

     

  9. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Robert Scholte commented

    This is how I think it should work for compilation:
    Based on the module descriptor:

    • direct static required modules should always be included
    • indirect required modules should always be included
    • indirect static required modules should not be included

    And I agree with Simone Bordet: it is very weird that --add-reads compiler.bug.app=ALL-UNNAMED doesn't work.

    To me the adjusted separation between 3.8.1 and 3.9.0 now looks better, maybe we've now hit an issue in the compiler.

  10. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Simone Bordet commented

    Robert Scholte I was thinking a variation of your algorithm above, like this:

    From module-info.java files:

    1. required modules should be included in module-path
    2. transitively resolved required modules should be included in module-path
    3. direct static requires modules should be included in module-path
    4. indirect static required modules should not be included in module-path

    From the POM:

    1. every dependency that belongs to any of the categories above (included the last one) should be included in module-path, if not already
    2. every dependency that does not belong to the categories above should be included in the class-path.

    For my specific case, jetty-util-ajax belongs to category module-info(4), and will be included in the module-path by pom(1), but junit belongs to category pom(2), so it can remain in the class-path (with the usual {}--add-reads <module>=ALL-UNNAMED{}).

    Thoughts?

  11. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Simone Bordet commented

    ??And I agree with Simone Bordet: it is very weird that --add-reads compiler.bug.app=ALL-UNNAMED doesn't work.??

    I'll send an email to compiler-dev, linking this issue.

    In any case, it will be fixed for Java 19, perhaps backported, so we still need a workaround in Maven, right?

  12. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Simone Bordet smart to add those numbers :) I just don't understand the add-reads is ignored in this case by the compiler.

  13. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Let's see what we'll get back from the compiler-dev list. The ResolvePathsRequest has an option to enforce extra modules, maybe we need to expose that as a workaround.

  14. jira-importer commented on Jan 21, 2022

    @jira-importer
    Author

    Simone Bordet commented

    There was a reply in the compiler-dev thread.

    IIUC, when the compiler.bug.service module is imported as a dependency, it does not import (because it's a requires static) the jetty-util-ajax jar.

    So when compiling the module compiler.bug.app, the "app" module sees the JSON class because of &#45;-add-reads compiler.bug.app=ALL-UNNAMED, but the "service" module still does not see it because it's not in the module-path and neither there is an &#45;-add-reads for the "service" module.

    So it seems a legit Maven Compiler Plugin issue/ feature that needs to be supported.

    In light of this information, is my algorithm or Robert Scholte's algorithm the right solution, or something else?

  15. 1 remaining item

  16. jira-importer commented on Jan 25, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    I find it strange we almost do not read anything from pom regarding (test?) dependencies.

    Shouldn't we automatically add test dependencies coming from the pom  in module-path  for test?

    not sure including static should be limited to test compilation only. If you look at the provided test project. not included static will fail compilation as there is 

    requires static org.eclipse.jetty.util.ajax

    and the dependency is marked as optional

    but it's required for compilation.

     

     

     

  17. jira-importer commented on Jan 25, 2022

    @jira-importer
    Author

    Martin Tzvetanov Grigorov commented

    https://issues.apache.org/jira/browse/MCOMPILER-482 is a similar issue like this one. You can take an inspiration from it for more test cases.

  18. jira-importer commented on Jan 25, 2022

    @jira-importer
    Author

    Robert Scholte commented

    Shouldn't we automatically add test dependencies coming from the pom in module-path for test?

    No, that would mean that for instance junit ends up on the modulepath, that doesn't make sense.
    Only jars that are used by both compile and test should be added to the modulepath.

  19. jira-importer commented on Jan 26, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    Robert Scholte please have a look codehaus-plexus/plexus-languages#106

    this is fixing both issues 

    and need compiler-plugin PR as well #82

    but to test m-c-p PR you need a local build of plexus-languages PR 

  20. jira-importer commented on Feb 1, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    ETA plexus-java released.

    still the m-c-p PR to merge

  21. jira-importer commented on Feb 1, 2022

    @jira-importer
    Author

    Olivier Lamy commented

    PR merge

  22. jira-importer commented on Jan 20, 2023

    @jira-importer
    Author

    Tamas Cservenak commented

    When building maven-compiler-plugin master with Maven 3.9.0 this IT fails

    [INFO] -------------------------------------------------
    [INFO] Build Summary:
    [INFO]   Passed: 62, Failed: 1, Errors: 0, Skipped: 5
    [INFO] -------------------------------------------------
    [ERROR] The following builds failed:
    [ERROR] *  MCOMPILER-481-requires-static-included/pom.xml
    [INFO] ------------------------------------------------- 
    

    Using

    [cstamas@urnebes maven-compiler-plugin]$ java -version
    openjdk version "11.0.17" 2022-10-18
    OpenJDK Runtime Environment Temurin-11.0.17+8 (build 11.0.17+8)
    OpenJDK 64-Bit Server VM Temurin-11.0.17+8 (build 11.0.17+8, mixed mode)
    [cstamas@urnebes maven-compiler-plugin]$ mvn -v
    Apache Maven 3.9.0-SNAPSHOT (f7ca0b697ac7223b42d982d92cad5af48c9d184d)
    Maven home: /home/cstamas/.sdkman/candidates/maven/current
    Java version: 11.0.17, vendor: Eclipse Adoptium, runtime: /home/cstamas/.sdkman/candidates/java/11.0.17-tem
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "6.1.6-200.fc37.x86_64", arch: "amd64", family: "unix"
    [cstamas@urnebes maven-compiler-plugin]$  
    

    Same happens with Java17 + mvn 3.9.0-SNAP

  23. jira-importer commented on Jan 21, 2023

    @jira-importer
    Author

    Robert Scholte commented

    Tamas Cservenak what makes you think it is a plugin bug? https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-compiler-plugin/job/master/ is green. Tested succesfully locally with 3.8.7, but failed with 3.9.0-SNAPSHOT. Looks more like a Maven bug.

  24. jira-importer commented on Jan 30, 2023

    @jira-importer
    Author

    Tamas Cservenak commented

    This seems like Surefire 3.0.0-M8 bug (as it is used by Maven 3.9 and Maven 4.0), as Maven 3.8.7 uses ancient 2.x surefire.... (the IT fails at test, compilation passes OK in 3.9.x)

  25. jira-importer commented on Jan 31, 2023

    @jira-importer
    Author

    Olivier Lamy commented

    Tamas Cservenak good catch!! maybe you can lock the surefire plugin version in the IT
    but again another difference between what m-compiler-p is doing for jpms and what surefire is doing... 🤦😩

  26. added
    bugSomething isn't working
    priority:blockerBlocks development and/or testing work, production could not run
    on Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpriority:blockerBlocks development and/or testing work, production could not run

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions