Copilot commented on code in PR #522:
URL:
https://github.com/apache/maven-build-cache-extension/pull/522#discussion_r3749205153
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -116,8 +116,23 @@ public void execute(
// so forks should rerun too
boolean forkedExecution =
lifecyclePhasesHelper.isForkedProject(project);
String projectName = getVersionlessProjectKey(project);
+ // Full caching (look up, restore and save) applies to a normal
lifecycle build, or to goals typed
+ // on the command line when they all map to a real phase after
clean (e.g. mvn compiler:compile).
+ boolean cacheEligible = !forkedExecution
+ && (source == Source.LIFECYCLE
+ || (source == Source.CLI
+ && cacheConfig.isCacheSingleGoal()
+ &&
isCacheableCliInvocation(mojoExecutions)));
+ // When a command-line goal forks a lifecycle (e.g. jetty:run
forks test-compile via
+ // @Execute(phase=...)), let that fork restore from cache but
never save. We skip forks that happen
+ // inside a normal build: that build already handles caching, and
joining in would just cause an
+ // extra, pointless cache lookup (see ForkedExecutionsTest /
ForkedExecutionCoreExtensionTest).
+ boolean forkedRestoreEligible = forkedExecution
+ && cacheConfig.isRestoreForkedExecutions()
+ && source == Source.LIFECYCLE
+ && isCliOriginatedFork(project);
Review Comment:
This eligibility check also accepts `@Execute(goal=...)` forks, whose
executions have no lifecycle phase. In that case
`resolveHighestLifecyclePhase()` returns null, the new null handling makes both
cached and post-cache segments empty, and a cache hit restores artifacts while
silently skipping the forked goal. Restrict restore-only caching to actual
post-clean phase executions so goal-only (and clean) forks continue to run
normally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]