Maven 编译器插件总是将一组源检测为“过时" [英] Maven compiler plugin always detecting a set of sources as "stale"
问题描述
已修复:这是 maven-compiler-plugin 3.1 中的已知错误
FIXED: this is a known bug in maven-compiler-plugin 3.1
我正在将 1000 多个 java-sources 项目的基于 ant 的构建转换为 maven.到目前为止一切顺利,但每次启动 mvn compile
它都会重新编译所有内容(而不是重用旧类)
I am converting an ant-based build of a 1000+ java-sources project to maven. So far so good, but every time launch mvn compile
it recompiles everything (instead of reusing old classes)
使用 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
...
(仅适用于某个包中的文件,它可能未从其余代码中引用;不是我的来源,我只是想对构建进行 mavenize)
(only for files in a certain package, which is possibly unreferenced from the rest of the code; not my sources, I am just trying to mavenize the build)
编译不会失败,更新时间戳的类正在生成
Compilation does not fail, and classes with updated timestamps are being generated at
/project_path/target/classes/package_path/AFile1.class
/project_path/target/classes/package_path/AFile2.class
...
但是,在查看时间戳时,java文件自昨天以来没有变化,类文件是最新的.为什么这些来源被确定为陈旧的?我该如何调试这个问题?
However, when looking at timestamps, the java files have not changed since yesterday, and the class files are current. Why are these sources determined to be stale? How can I debug this issue?.
即使没有发生任何更改,也必须重新编译 1k+ 文件,这很麻烦...
It is a drag to have to recompile 1k+ files even when no changes have occurred...
示例输出:
$ 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] ------------------------------------------------------------------------
推荐答案
这是 maven-compiler-plugin 3.1 中的一个已知问题.它正在 https://issues.apache.org/jira/browse/MCOMPILER-209 中被跟踪(useIncrementalCompilation
标志已损坏).
This is a known problem in maven-compiler-plugin 3.1. It is being tracked in https://issues.apache.org/jira/browse/MCOMPILER-209 (the useIncrementalCompilation
flag is broken).
该问题与另一个 3.1 错误无关,https://issues.apache.org/jira/browse/MCOMPILER-205(其中不产生 .class 输出的文件总是被标记为 'stale').
The problem is unrelated to another 3.1 bug, https://issues.apache.org/jira/browse/MCOMPILER-205 (where files that do not produce .class outputs are always flagged as 'stale').
进一步测试后,回到 3.0 并没有真正解决问题(它只在下一次 mvn clean compile
之前有效.然而,正如 Michael Lemke 在评论中建议的那样,标记 useIncrementalCompilation
到 false
是一个可行的替代品;现在,每次只重新编译有问题的包(而不是整个代码库).
After testing further, going back to 3.0 did not actually fix the problem (it only works until the next mvn clean compile
. However, as Michael Lemke suggests in comments, marking useIncrementalCompilation
to false
is a workable substitute; now, only the offending package gets recompiled each time (instead of the whole code-base).
这篇关于Maven 编译器插件总是将一组源检测为“过时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!