apache / apache/maven-compiler-plugin
[MCOMPILER-597] exports ... to ... does not create a correct modulePath
- Dominant language
- Java
- Stars
- 261
- Forks
- 191
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 8
Description
**[Caleb Cushing](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=xenoterracide)** opened **[MCOMPILER-597](https://issues.apache.org/jira/browse/MCOMPILER-597?redirect=false)** and commented
When using a `module-info` with the `exports ... to ...` directive, the `modulePath` is generated incorrectly.
Given the following `module-info.java` and the corresponding `pom.xml` files, the following warning is triggered:
```java
import org.jspecify.annotations.NullMarked;
/**
* Provide an easy to include {@code TestApplication} implementation for {@code com.xenoterracide} Spring Boot
* Applications. Simply include the module on your classpath.
*/
@NullMarked module com.xenoterracide {
exports com.xenoterracide to spring.context, spring.beans;
opens com.xenoterracide to spring.core;
requires spring.context;
requires spring.boot.autoconfigure;
requires static org.jspecify;
}
```
```
[DEBUG] Classpath:
[DEBUG] /home/xeno/IdeaProjects/spring-app-commons/test-app/target/classes
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-core/6.1.11/spring-core-6.1.11.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-jcl/6.1.11/spring-jcl-6.1.11.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/boot/spring-boot/3.3.2/spring-boot-3.3.2.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-aop/6.1.11/spring-aop-6.1.11.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-expression/6.1.11/spring-expression-6.1.11.jar
[DEBUG] /home/xeno/.m2/repository/io/micrometer/micrometer-observation/1.13.2/micrometer-observation-1.13.2.jar
[DEBUG] /home/xeno/.m2/repository/io/micrometer/micrometer-commons/1.13.2/micrometer-commons-1.13.2.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-beans/6.1.11/spring-beans-6.1.11.jar
[DEBUG] Modulepath:
[DEBUG] /home/xeno/.m2/repository/org/jspecify/jspecify/1.0.0/jspecify-1.0.0.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/3.3.2/spring-boot-autoconfigure-3.3.2.jar
[DEBUG] /home/xeno/.m2/repository/org/springframework/spring-context/6.1.11/spring-context-6.1.11.jar
[WARNING] /home/xeno/IdeaProjects/spring-app-commons/test-app/src/main/java/module-info.java:[8,54] module not found: spring.beans
[WARNING] /home/xeno/IdeaProjects/spring-app-commons/test-app/src/main/java/module-info.java:[9,36] module not found: spring.core
```
```xml
4.0.0
com.xenoterracide
spring-app-commons
1.0-SNAPSHOT
pom
Common Modules for a Spring Boot Application
test-app
17
UTF-8
UTF-8
org.springframework.boot
spring-boot-dependencies
3.3.2
pom
import
org.jspecify
jspecify
1.0.0
org.assertj
assertj-core
3.26.3
test
maven-compiler-plugin
3.13.0
17
-XDcompilePolicy=simple
-Xplugin:ErrorProne
com.google.errorprone
error_prone_core
2.30.0
maven-surefire-plugin
3.3.1
```
```xml
4.0.0
com.xenoterracide
spring-app-commons
1.0-SNAPSHOT
../pom.yml
test-app
org.jspecify
jspecify
org.springframework
spring-core
org.springframework.boot
spring-boot-autoconfigure
org.springframework
spring-context
org.springframework
spring-beans
org.springframework
spring-test
runtime
org.springframework.boot
spring-boot-test
test
org.springframework.boot
spring-boot-test-autoconfigure
test
org.junit.jupiter
junit-jupiter-engine
test
org.junit.jupiter
junit-jupiter-api
test
org.assertj
assertj-core
test
```
This issue would not occur if `spring-beans` and `spring-core` were included on the modulepath. I believe that Spring is generating a class that implicitly imports my class, resulting in a scenario where `spring-beans` requires my module, but my module does not require `spring-beans`. Removing this export would result in a build failure.
note: I need to make these the right scope again because they are runtime not compile time. Also, I'm migrating from gradle where I did not receive this warning.
---
**Affects:** 3.13.0
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the warning with the provided module-info.java and the two pom.xml files using Maven Compiler Plugin 3.13.0. Start by tracing how the compiler plugin builds the classpath and modulepath for qualified exports; done means the modulePath includes the required modules or no longer produces the incorrect module-not-found warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100