Maven编译器插件始终将一组源检测为“过时”

2022-08-31 14:59:39

修复:这是 maven 编译器插件 3.1 中的一个已知错误

我正在将一个1000多个java源代码项目的基于蚂蚁的构建转换为maven。到目前为止,一切都很好,但每次启动它都会重新编译所有内容(而不是重用旧类)mvn compile

使用具有以下条件的报告mvn -X compile

[DEBUG] Stale source detected: /project_path/src/main/java/package_path/AFile1.java
[DEBUG] Stale source detected: /project_path/src/main/java/package_path/AFile2.java
...

(仅适用于某个包中的文件,该文件可能未从代码的其余部分引用;不是我的消息来源,我只是试图对构建进行人工处理)

编译不会失败,并且正在生成时间戳更新的类

/project_path/target/classes/package_path/AFile1.class
/project_path/target/classes/package_path/AFile2.class
...

但是,在查看时间戳时,Java 文件自昨天以来没有更改,并且类文件是最新的。为什么这些来源被确定为陈旧?如何调试此问题?

即使没有发生任何更改,也必须重新编译1k +文件,这是一种拖累......


示例输出:

$ mvn clean compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 1.9.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for net.sourceforge:jffmpeg:jar:1.1.0 is missing, no dependency information available
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ my-project ---
[INFO] Deleting /project_path/target
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ my-project ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /project_path/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ my-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1162 source files to project_path/target/classes
....
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.215s
[INFO] Finished at: Tue Jul 30 12:42:25 CEST 2013
[INFO] Final Memory: 25M/429M
[INFO] ------------------------------------------------------------------------



$ mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 1.9.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for net.sourceforge:jffmpeg:jar:1.1.0 is missing, no dependency information available
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ my-project ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /project_path/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ my-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1162 source files to /project_path/target/classes
... 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.140s
[INFO] Finished at: Tue Jul 30 12:42:44 CEST 2013
[INFO] Final Memory: 22M/379M
[INFO] ------------------------------------------------------------------------

答案 1

这是 maven-compiler-plugin 3.1 中的一个已知问题。它正在 https://issues.apache.org/jira/browse/MCOMPILER-209 中被跟踪(标志已损坏)。useIncrementalCompilation

该问题与另一个3.1错误无关,https://issues.apache.org/jira/browse/MCOMPILER-205(其中不产生.class输出的文件始终标记为“过时”)。

经过进一步的测试,回到3.0实际上并没有解决问题(它只工作到下一个.但是,正如Michael Lemke在评论中建议的那样,标记为是一个可行的替代品;现在,每次只有违规的包被重新编译(而不是整个代码库)。mvn clean compileuseIncrementalCompilationfalse


答案 2

Maven 可能会显示如下消息:

[信息]检测到更改 - 重新编译模块!

因为项目中有一个空的 java 文件(或全部注释掉),该文件永远不会编译为类文件。

您可以通过使用 -X 运行 maven 来确定 maven 重建的原因。请看上面的消息附近。


推荐