This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git


The following commit(s) were added to refs/heads/master by this push:
     new 5dfbfa7  #218 Do not lookup for existing cache with given skip cache 
and cache enabled parameters   (#413)
5dfbfa7 is described below

commit 5dfbfa792bbf53bc6adc2007afa903a209ab0347
Author: Ivan <[email protected]>
AuthorDate: Sun Jan 18 02:22:01 2026 +0100

    #218 Do not lookup for existing cache with given skip cache and cache 
enabled parameters   (#413)
    
    * Do not lookup for existing cache with
    maven.build.cache.enable=false
    and
    maven.build.cache.skipCache=true
    to avoid build failure
    
    Co-authored-by: Yury Yerokhin <[email protected]>
    
    * Update src/test/projects/skip-cache-param/src/main/java/Main.java
    
    Co-authored-by: Erik Meuwese <[email protected]>
    
    ---------
    
    Co-authored-by: Yury Yerokhin <[email protected]>
    Co-authored-by: Erik Meuwese <[email protected]>
---
 .../BuildCacheMojosExecutionStrategy.java          |   2 +-
 .../maven/buildcache/its/SkipCacheParamTest.java   | 103 +++++++++++++++++++++
 .../projects/skip-cache-param/.mvn/extensions.xml  |  23 +++++
 src/test/projects/skip-cache-param/pom.xml         |  25 +++++
 .../skip-cache-param/src/main/java/Main.java       |   5 +
 5 files changed, 157 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
 
b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
index 952dd43..06a6fbc 100644
--- 
a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
+++ 
b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
@@ -134,7 +134,7 @@ public void execute(
                 for (MojoExecution mojoExecution : cleanPhase) {
                     mojoExecutionRunner.run(mojoExecution);
                 }
-                if (cacheState == INITIALIZED || skipCache) {
+                if (cacheState == INITIALIZED) {
                     result = cacheController.findCachedBuild(session, project, 
mojoExecutions, skipCache);
                 }
             } else {
diff --git 
a/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java 
b/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java
new file mode 100644
index 0000000..9f6b1da
--- /dev/null
+++ b/src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.buildcache.its;
+
+import java.util.List;
+
+import org.apache.maven.buildcache.its.junit.IntegrationTest;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.junit.jupiter.api.Test;
+
+@IntegrationTest("src/test/projects/skip-cache-param")
+public class SkipCacheParamTest {
+
+    @Test
+    void skipCacheAndCacheDisabled(Verifier verifier) throws 
VerificationException {
+        // cache.enabled=false , cache.skipCache=false => cache should NOT be 
created
+        verifier.setAutoclean(false);
+        verifier.setLogFileName("../log-0.txt");
+        verifier.addCliOption("-Dmaven.build.cache.enabled=false");
+        verifier.addCliOption("-Dmaven.build.cache.skipCache=false");
+
+        verifier.executeGoal("package");
+
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog("Building jar:");
+        verifyTextNotInLog(verifier, "Saved Build to local file:");
+    }
+
+    @Test
+    void cacheEnabledShouldCreateCache(Verifier verifier) throws 
VerificationException {
+        // cache.enabled=true , cache.skipCache=false => cache should be 
created, normal scenario
+        verifier.setAutoclean(false);
+        verifier.setLogFileName("../log-1.txt");
+        verifier.addCliOption("-Dmaven.build.cache.enabled=true");
+        verifier.addCliOption("-Dmaven.build.cache.skipCache=false");
+
+        verifier.executeGoal("package");
+
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog("Going to calculate checksum for project");
+    }
+
+    @Test
+    void disabledCacheAndSkipCacheShouldNotCreateCache(Verifier verifier) 
throws VerificationException {
+        // cache.enabled=false , cache.skipCache=true => cache should NOT be 
created
+        verifier.setAutoclean(false);
+
+        verifier.setLogFileName("../log-2.txt");
+        verifier.addCliOption("-Dmaven.build.cache.enabled=false");
+        verifier.addCliOption("-Dmaven.build.cache.skipCache=true");
+
+        verifier.executeGoal("package");
+
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog("Building jar:");
+        verifyTextNotInLog(verifier, "Saved Build to local file:");
+    }
+
+    @Test
+    void enabledCacheAndSkippingCacheShouldNotCreateCache(Verifier verifier) 
throws VerificationException {
+        // cache.enabled=true , cache.skipCache= true => cache should not be 
read, only be created
+        verifier.setAutoclean(false);
+        verifier.setLogFileName("../log-3.txt");
+        verifier.addCliOption("-Dmaven.build.cache.enabled=true");
+        verifier.addCliOption("-Dmaven.build.cache.skipCache=true");
+
+        verifier.executeGoal("package");
+
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog("Saved Build to local file:");
+
+        // repeating one more time should not trigger a lookup
+        verifier.executeGoal("package");
+
+        verifyTextNotInLog(verifier, "Found cached build, restoring");
+    }
+
+    private static void verifyTextNotInLog(Verifier verifier, String text) 
throws VerificationException {
+        List<String> lines = verifier.loadFile(verifier.getBasedir(), 
verifier.getLogFileName(), false);
+        for (String line : lines) {
+            if (Verifier.stripAnsi(line).contains(text)) {
+                throw new VerificationException("Text found in log: " + text);
+            }
+        }
+    }
+}
diff --git a/src/test/projects/skip-cache-param/.mvn/extensions.xml 
b/src/test/projects/skip-cache-param/.mvn/extensions.xml
new file mode 100644
index 0000000..15c170e
--- /dev/null
+++ b/src/test/projects/skip-cache-param/.mvn/extensions.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<extensions>
+    <extension>
+        <groupId>org.apache.maven.extensions</groupId>
+        <artifactId>maven-build-cache-extension</artifactId>
+        <version>${projectVersion}</version>
+    </extension>
+</extensions>
diff --git a/src/test/projects/skip-cache-param/pom.xml 
b/src/test/projects/skip-cache-param/pom.xml
new file mode 100644
index 0000000..552054a
--- /dev/null
+++ b/src/test/projects/skip-cache-param/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.mayweg</groupId>
+  <artifactId>untitled</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <properties>
+  </properties>
+</project>
diff --git a/src/test/projects/skip-cache-param/src/main/java/Main.java 
b/src/test/projects/skip-cache-param/src/main/java/Main.java
new file mode 100644
index 0000000..2d15bb7
--- /dev/null
+++ b/src/test/projects/skip-cache-param/src/main/java/Main.java
@@ -0,0 +1,5 @@
+public class Main {
+    public static void main(String[] args) {
+        System.out.println("Hello World!");
+    }
+}

Reply via email to