Skip to content

[MCOMPILER-597] exports ... to ... does not create a correct modulePath #876

Open

Description

@jira-importer

Caleb Cushing opened MCOMPILER-597 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:

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 version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xenoterracide</groupId>
  <artifactId>spring-app-commons</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>Common Modules for a Spring Boot Application</name>
  <modules>
    <module>test-app</module>
  </modules>
  <properties>
    <java.version>17</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>3.3.2</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.jspecify</groupId>
        <artifactId>jspecify</artifactId>
        <version>1.0.0</version>
      </dependency>
      <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.26.3</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.13.0</version>
          <configuration>
            <release>17</release>
            <compilerArgs>
              <compilerArg>-XDcompilePolicy=simple</compilerArg>
              <compilerArg>-Xplugin:ErrorProne</compilerArg>
            </compilerArgs>
            <annotationProcessorPaths>
              <annotationProcessorPath>
                <groupId>com.google.errorprone</groupId>
                <artifactId>error_prone_core</artifactId>
                <version>2.30.0</version>
              </annotationProcessorPath>
            </annotationProcessorPaths>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.3.1</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.xenoterracide</groupId>
    <artifactId>spring-app-commons</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.yml</relativePath>
  </parent>
  <artifactId>test-app</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.jspecify</groupId>
      <artifactId>jspecify</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-test-autoconfigure</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

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

Activity

  1. added
    bug
    priority:major
    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

No one assigned

    Labels

    bugpriority:major

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions