@@ -100,17 +100,21 @@ public BuildCacheMojosExecutionStrategy(
100100 public void execute (
101101 List <MojoExecution > mojoExecutions , MavenSession session , MojoExecutionRunner mojoExecutionRunner )
102102 throws LifecycleExecutionException {
103+
103104 try {
104105 final MavenProject project = session .getCurrentProject ();
105106 final Source source = getSource (mojoExecutions );
106107
107108 // execute clean bound goals before restoring to not interfere/slowdown clean
108109 CacheState cacheState = DISABLED ;
109110 CacheResult result = CacheResult .empty ();
110- boolean skipCache = cacheConfig .isSkipCache () || MavenProjectInput .isSkipCache (project );
111+ boolean skipCache =
112+ cacheConfig .isSkipCache () || MavenProjectInput .isSkipCache (project ) || isGoalClean (mojoExecutions );
111113 boolean cacheIsDisabled = MavenProjectInput .isCacheDisabled (project );
112- // Forked execution should be thought as a part of originating mojo internal implementation
113- // If forkedExecution is detected, it means that originating mojo is not cached so forks should rerun too
114+ // Forked execution should be thought as a part of originating mojo internal
115+ // implementation
116+ // If forkedExecution is detected, it means that originating mojo is not cached
117+ // so forks should rerun too
114118 boolean forkedExecution = lifecyclePhasesHelper .isForkedProject (project );
115119 String projectName = getVersionlessProjectKey (project );
116120 List <MojoExecution > cleanPhase = null ;
@@ -178,13 +182,29 @@ public void execute(
178182 }
179183
180184 /**
181- * Cache configuration could demand to restore some files in the project directory (generated sources or even arbitrary content)
182- * If an error occurs during or after this kind of restoration AND a clean phase was required in the build :
183- * we execute an extra clean phase to remove any potential partially restored files
185+ * Check if the current mojo execution is for the clean goal
186+ *
187+ * @param mojoExecutions the mojo executions
188+ * @return true if the goal is clean and it is the only goal, false otherwise
189+ */
190+ private boolean isGoalClean (List <MojoExecution > mojoExecutions ) {
191+ if (mojoExecutions .stream ().allMatch (mojoExecution -> "clean" .equals (mojoExecution .getLifecyclePhase ()))) {
192+ LOGGER .info ("Build cache is disabled for 'clean' goal." );
193+ return true ;
194+ }
195+ return false ;
196+ }
197+
198+ /**
199+ * Cache configuration could demand to restore some files in the project
200+ * directory (generated sources or even arbitrary content)
201+ * If an error occurs during or after this kind of restoration AND a clean phase
202+ * was required in the build, we execute an extra clean phase to remove any
203+ * potential partially restored files.
184204 *
185205 * @param cacheRestorationStatus the restoration status
186- * @param cleanPhase clean phase mojos
187- * @param mojoExecutionRunner mojo runner
206+ * @param cleanPhase clean phase mojos
207+ * @param mojoExecutionRunner mojo runner
188208 * @throws LifecycleExecutionException
189209 */
190210 private void executeExtraCleanPhaseIfNeeded (
@@ -258,15 +278,6 @@ private CacheRestorationStatus restoreProject(
258278 LOGGER .info (
259279 "Mojo execution is forced by project property: {}" ,
260280 cacheCandidate .getMojoDescriptor ().getFullGoalName ());
261- // need maven 4 as minumum
262- // mojoExecutionScope.seed(
263- // org.apache.maven.api.plugin.Log.class,
264- // new DefaultLog(LoggerFactory.getLogger(
265- // cacheCandidate.getMojoDescriptor().getFullGoalName())));
266- // mojoExecutionScope.seed(Project.class, ((DefaultSession)
267- // session.getSession()).getProject(project));
268- // mojoExecutionScope.seed(
269- // org.apache.maven.api.MojoExecution.class, new DefaultMojoExecution(cacheCandidate));
270281 mojoExecutionRunner .run (cacheCandidate );
271282 } else {
272283 LOGGER .info (
@@ -413,7 +424,8 @@ boolean isParamsMatched(
413424 * - all absolute paths under project root to be relativized for portability
414425 * - redundant '..' and '.' to be removed to have consistent views on all paths
415426 * - all relative paths are considered portable and should not be touched
416- * - absolute paths outside of project directory could not be deterministically relativized and not touched
427+ * - absolute paths outside of project directory could not be deterministically
428+ * relativized and not touched
417429 */
418430 private static String normalizedPath (Path path , Path baseDirPath ) {
419431 boolean isProjectSubdir = path .isAbsolute () && path .startsWith (baseDirPath );
0 commit comments