Skip to content
Open
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 @@ -129,7 +129,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 {
Expand Down
103 changes: 103 additions & 0 deletions src/test/java/org/apache/maven/buildcache/its/SkipCacheParamTest.java
Original file line number Diff line number Diff line change
@@ -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 {
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The test method name and comment contradict each other. The method is named enabledCacheAndSkippingCacheShouldNotCreateCache but the comment on line 78 states "cache should not be read, only be created" and the test verifies on line 87 that the cache is saved. The method name should reflect that cache IS created but not read/restored.

Suggested change
void enabledCacheAndSkippingCacheShouldNotCreateCache(Verifier verifier) throws VerificationException {
void enabledCacheAndSkippingCacheShouldCreateButNotReadCache(Verifier verifier) throws VerificationException {

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

I honestly find existing test name quite good since it does address the current issue: cache is being created when it's not the desired result

// cache.enabled=true , cache.skipCache= true => cache should not be read, only be created
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The comment has a grammatical issue with inconsistent spacing: "cache.skipCache= true" should be "cache.skipCache=true" (missing space before equals sign, or add space after it for consistency).

Suggested change
// cache.enabled=true , cache.skipCache= true => cache should not be read, only be created
// cache.enabled=true , cache.skipCache=true => cache should not be read, only be created

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

how important is this? I would ignore such suggestion this as well

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);
}
}
}
}
23 changes: 23 additions & 0 deletions src/test/projects/skip-cache-param/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -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>
25 changes: 25 additions & 0 deletions src/test/projects/skip-cache-param/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
5 changes: 5 additions & 0 deletions src/test/projects/skip-cache-param/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}