Recompile when dependencies change - #1102
Conversation
3d01630 to
665f6cf
Compare
665f6cf to
096cfb4
Compare
| } | ||
| if (changedDependency != null) { | ||
| if (configuration.log.isDebugEnabled() || configuration.showChanges) { | ||
| configuration.log.info("\tNew dependency detected: " + changedDependency.toAbsolutePath()); |
There was a problem hiding this comment.
I wouldn't log this above debug level
There was a problem hiding this comment.
The log.info is there because it is possible to get the line printed with user supplied maven.compiler.showCompilationChanges property. If it were log.debug it would not print if the user asked via the property. I can change it to debug for configuration.log.isDebugEnabled() and keep the info for configuration.showChanges. But that seems unnecessarily nuanced.
There was a problem hiding this comment.
I only see one call of this method?
There was a problem hiding this comment.
I agree here with @wilx not needed to do more complicated
| } | ||
| } | ||
|
|
||
| List<Path> files; |
There was a problem hiding this comment.
This belongs inside the try, as does all the code that depends on it. Don't split variable declaration and initialization
| changedDependency = file; | ||
| } | ||
| } catch (IOException e) { | ||
| if (!unreadable) { |
There was a problem hiding this comment.
should you just break out of the loop in this case?
There was a problem hiding this comment.
Fixed by merging the two try/catch regions.
|
|
||
| if (hasPreviousState && !oldState.equals(newState)) { | ||
| if (configuration.log.isDebugEnabled() || configuration.showChanges) { | ||
| logChanges(oldState, newState, configuration.log); |
There was a problem hiding this comment.
checking debug here is good, but it's info level in the logChanges method. logChanges should log at debug level
There was a problem hiding this comment.
It is already gated by maven.compiler.showCompilationChanges property.
| } | ||
| if (changedDependency != null) { | ||
| if (configuration.log.isDebugEnabled() || configuration.showChanges) { | ||
| configuration.log.info("\tNew dependency detected: " + changedDependency.toAbsolutePath()); |
There was a problem hiding this comment.
I only see one call of this method?
| * | ||
| * @return {@code true} if at least one single dependency has changed. | ||
| */ | ||
| protected boolean isDependencyChanged() { |
There was a problem hiding this comment.
This method should be retained with protected access, even if it's implementation changes
There was a problem hiding this comment.
I'm not sure if we need to preserve all plugin internal methods.
Maven plugin is not library so should be not used as standard dependencies.
Even more we only recommended use as plugin not dependencies
https://maven.apache.org/plugins/maven-compiler-plugin/dependency-info.html
|
@wilx please rebase |
Persist ordered classpath and module-path dependency state between plugin invocations. Compare file metadata and stable directory fingerprints while preserving current-build timestamp detection in the same scan, so removed, reordered, relocated, and same-path replaced dependencies trigger recompilation without duplicate directory traversal. Fixes apache#1087
e237a3a to
12013c6
Compare
Done. |
|
@elharo does your comments resolved? |
elharo
left a comment
There was a problem hiding this comment.
some of my original comments are answered, a couple are not
| * | ||
| * @return {@code true} if at least one single dependency has changed. | ||
| */ | ||
| protected boolean isDependencyChanged() { |
| StringBuilder buffer = new StringBuilder(bytes.length * 2); | ||
| for (byte value : bytes) { | ||
| int unsigned = value & 0xFF; | ||
| buffer.append(Character.forDigit(unsigned >>> 4, 16)); |
There was a problem hiding this comment.
I'd just use Integer.toHexString here
Preserve the fixed two-character representation by prepending a zero when the converted byte has only one hexadecimal digit.
Summary
dependencies.lststate filechanged dependencyrebuild reason when dependencies are added, removed, reordered, relocated, or replaced at the same pathWhy
The 3.x incremental check only considered dependency timestamps relative to the current Maven session. It could therefore miss a dependency removed between invocations or a JAR replaced at the same path before the next invocation, leaving stale application bytecode.
The persisted comparison and the existing session-relative fallback are now consolidated. A missing baseline still detects dependencies rebuilt during the current Maven invocation, while unchanged builds no longer walk exploded dependencies once for persisted state and again for the timestamp fallback.
Validation
JAVA_HOME=/opt/jdks/latest-8 /opt/maven/latest/bin/mvn clean verify— 36 tests passedJAVA_HOME=/opt/jdks/latest-21 /opt/maven/latest/bin/mvn clean verify— 36 tests passedJAVA_HOME=/opt/jdks/latest-21 /opt/maven/latest/bin/mvn -Prun-its clean verify— 78 builds passed, 5 environment-specific skipsFixes #1087
Following this checklist to help us incorporate your
contribution quickly and easily:
[MCOMPILER-XXX]convention is not applicable because this is tracked as GitHub issue No recompilation if the dependencies have changed #1087.mvn clean verify.mvn -Prun-its clean verify.If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.