Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ private static Path addDependencies(
* The directory digest covers each relevant file's relative path, size and modification time.
*/
private static ModificationState modificationState(Path dependency, ScanContext context) {
if (Files.notExists(dependency)) {
// A reactor module with no sources for this output kind (e.g. no main sources, so
// `target/classes` is never created) still appears on the classpath. Treat it like an
// empty directory instead of letting `readAttributes` below fail with a spurious
// "I/O error reading dependency state" warning and an "unreadable" state that never
// compares equal across builds, which defeated incremental compilation (forced a
// recompile on every run).
return new ModificationState(0 + ":" + toHexString(newDigest().digest()), null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Style nit: 0 + ":" is a redundant int-to-String promotion that looks like a mistake. Prefer the string literal directly:

Suggested change
return new ModificationState(0 + ":" + toHexString(newDigest().digest()), null);
return new ModificationState("0:" + toHexString(newDigest().digest()), null);

(Note: the existing PR #1125 uses the same pattern — worth fixing there too.)

}
if (!Files.isDirectory(dependency)) {
try {
BasicFileAttributes attributes = readAttributes(dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class DependencyStateTest {
Expand Down Expand Up @@ -113,6 +116,33 @@ void preservesRepeatedDependencyEntriesAndPathKinds() throws Exception {
assertTrue(state.get(2).startsWith("modulepath:"));
}

@Test
void treatsMissingDependencyDirectoryAsEmptyWithoutWarningOrForcedRebuild() throws Exception {
Path dependency = temporaryDirectory.resolve("classes-not-yet-compiled");
IncrementalBuildHelper helper = mock(IncrementalBuildHelper.class);
when(helper.getMojoStatusDirectory()).thenReturn(temporaryDirectory.toFile());
Log log = mock(Log.class);

DependencyState.Configuration configuration =
new DependencyState.Configuration(Collections.emptySet(), BUILD_START, 0, log, false);
List<String> classpath = Collections.singletonList(dependency.toString());

assertFalse(DependencyState.hasChanged(
helper,
temporaryDirectory.resolve("output").toFile(),
classpath,
Collections.emptyList(),
configuration));
assertFalse(DependencyState.hasChanged(
helper,
temporaryDirectory.resolve("output").toFile(),
classpath,
Collections.emptyList(),
configuration));

verify(log, never()).warn(contains("I/O error"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Incomplete test coverage: This test only verifies the missing → no warning + no rebuild path. It never creates classes-not-yet-compiled and then calls hasChanged again to verify it returns true, which is the critical caching correctness case: once the directory appears, the compiler must detect a change and recompile. Without this, a caching regression (stale empty-state that prevents recompile when the directory later materialises) could slip through undetected.

PR #1125 already covers this transition in its commit 9ecf77f. Please defer to that PR.

}

@Test
void retainsCurrentBuildDetectionWhenStatusDirectoryIsUnavailable() throws Exception {
Path dependency = dependency("dependency.jar", 3_000, 1);
Expand Down
Loading