java build_error ai_generated true

在项目 my-app 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) 失败:编译失败:找不到模块 com.example.util

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project my-app: Compilation failure: module not found: com.example.util

ID: java/maven-plugin-execution-error

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-08-14首次发现

版本兼容性

版本状态引入弃用备注
9+ active

根因分析

Java 模块系统需要显式模块声明,并且所需的模块缺失或未在 module-info.java 中声明。

English

The Java module system requires explicit module declarations, and a required module is missing or not declared in module-info.java.

generic

解决方案

  1. 95% 成功率 Add the required module to module-info.java
    module my.app { requires com.example.util; }
  2. 80% 成功率 Use --add-modules compiler argument if module is on classpath
    <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><compilerArgs><arg>--add-modules</arg><arg>com.example.util</arg></compilerArgs></configuration></plugin>

无效尝试

常见但无效的做法:

  1. Removing module-info.java entirely 70% 失败

    The project may be designed for Java 9+, and removing module-info can break encapsulation.

  2. Adding the module to the classpath instead of module path 80% 失败

    Maven compiler plugin may still enforce module path for Java 9+.