Skip to content

Commit 55c6e7a

Browse files
cowwocclaude
authored andcommitted
Add detailed comments and logging for compile-only cache saving
- Document why attached resource bookkeeping reset is needed - Explain that outputs are attached for ALL lifecycle phases - Add debug logging when saving compile-only cache entries - Address reviewer feedback from PR #176 about pre-compile phase support
1 parent 19f4a0a commit 55c6e7a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ public void save(
498498
final MavenProject project = context.getProject();
499499
final MavenSession session = context.getSession();
500500
try {
501+
// Reset attached resource bookkeeping to ensure clean state per save invocation.
502+
// This prevents stale artifacts from previous builds within the same session
503+
// from polluting the current cache entry (critical for multi-module builds).
501504
attachedResourcesPathsById.clear();
502505
attachedResourceCounter = 0;
503506

@@ -506,9 +509,20 @@ public void save(
506509
final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact();
507510
final boolean hasPackagePhase = project.hasLifecyclePhase("package");
508511

512+
// Attach configured outputs for ALL lifecycle phases (including compile-only builds).
513+
// This ensures compile-only cache entries contain necessary outputs (e.g., classes, module-info)
514+
// for subsequent builds that restore from cache and continue with later phases.
515+
// Addresses issues #393, #259, #340 where JPMS modules failed after compile-only cache hits.
509516
attachGeneratedSources(project);
510517
attachOutputs(project);
511518

519+
if (!hasPackagePhase && LOGGER.isDebugEnabled()) {
520+
LOGGER.debug(
521+
"Saving cache entry for compile-only build (no package phase) for project {}. "
522+
+ "Attached outputs will be available for restoration in subsequent builds.",
523+
project.getArtifactId());
524+
}
525+
512526
final List<org.apache.maven.artifact.Artifact> attachedArtifacts = project.getAttachedArtifacts() != null
513527
? project.getAttachedArtifacts()
514528
: Collections.emptyList();

0 commit comments

Comments
 (0)