Copilot commented on code in PR #493:
URL:
https://github.com/apache/maven-build-cache-extension/pull/493#discussion_r4398961536
##########
src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java:
##########
@@ -486,6 +486,13 @@ public ArtifactRestorationReport
restoreProjectArtifacts(CacheResult cacheResult
if (!project.hasLifecyclePhase("package")) {
project.addLifecyclePhase("package");
}
+ } else if (restoredProjectArtifact != null) {
+ // Directory artifact (target/classes from compile-only build).
+ // Point the existing project artifact at the restored
directory so reactor dependency
+ // resolution can locate this module's compiled output. Don't
replace the artifact:
+ // RestoredArtifact.getFile() always re-routes through
restoreToDiskConsumer, which would
+ // break later phases (e.g. jar:jar) that update the file via
setFile().
+
project.getArtifact().setFile(restoredProjectArtifact.getFile());
Review Comment:
After setting the project artifact file, consider also explicitly marking
the artifact as resolved (e.g., via `setResolved(true)` on the project
artifact) if the Maven artifact implementation in use does not infer
resolved-state from `setFile()`. This helps ensure no later resolution step
still treats the artifact as unresolved and attempts remote resolution despite
the file being present.
##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.Arrays;
+
+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;
+
+/**
+ * Reproducer for <a
href="https://github.com/apache/maven-build-cache-extension/issues/492">Issue
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's
compiled
+ * output but, because no jar was produced in the original cached build,
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+ @Test
+ void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier)
throws VerificationException {
+ verifier.setAutoclean(false);
+
+ verifier.setLogFileName("../log-compile-1.txt");
+ verifier.executeGoals(Arrays.asList("clean", "compile"));
+ verifier.verifyErrorFreeLog();
+
+ verifier.setLogFileName("../log-compile-2.txt");
Review Comment:
Writing verifier logs into the parent directory (`../...`) can cause
cross-test interference (especially under parallel test execution or shared
working directories) and can also fail in constrained CI sandboxes. Prefer
writing logs under the test project directory (or a per-test unique path) to
avoid collisions.
##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.Arrays;
+
+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;
+
+/**
+ * Reproducer for <a
href="https://github.com/apache/maven-build-cache-extension/issues/492">Issue
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's
compiled
+ * output but, because no jar was produced in the original cached build,
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+ @Test
+ void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier)
throws VerificationException {
+ verifier.setAutoclean(false);
+
+ verifier.setLogFileName("../log-compile-1.txt");
+ verifier.executeGoals(Arrays.asList("clean", "compile"));
+ verifier.verifyErrorFreeLog();
+
+ verifier.setLogFileName("../log-compile-2.txt");
Review Comment:
Writing verifier logs into the parent directory (`../...`) can cause
cross-test interference (especially under parallel test execution or shared
working directories) and can also fail in constrained CI sandboxes. Prefer
writing logs under the test project directory (or a per-test unique path) to
avoid collisions.
##########
src/test/java/org/apache/maven/buildcache/its/CompileOnlyReactorRestoreTest.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.Arrays;
+
+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;
+
+/**
+ * Reproducer for <a
href="https://github.com/apache/maven-build-cache-extension/issues/492">Issue
#492</a>:
+ * {@code clean compile} twice in a multi-module reactor fails to resolve the
upstream module.
+ *
+ * <p>On the second run the cache extension restores the upstream module's
compiled
+ * output but, because no jar was produced in the original cached build,
downstream
+ * dependency resolution falls through to remote repositories with
+ * {@code Could not find artifact ...:jar:...-SNAPSHOT}.
+ */
+@IntegrationTest("src/test/projects/issue-393-compile-restore")
+class CompileOnlyReactorRestoreTest {
+
+ @Test
+ void cleanCompileTwiceResolvesUpstreamFromReactorCache(Verifier verifier)
throws VerificationException {
+ verifier.setAutoclean(false);
+
+ verifier.setLogFileName("../log-compile-1.txt");
+ verifier.executeGoals(Arrays.asList("clean", "compile"));
+ verifier.verifyErrorFreeLog();
+
+ verifier.setLogFileName("../log-compile-2.txt");
+ verifier.executeGoals(Arrays.asList("clean", "compile"));
+ verifier.verifyErrorFreeLog();
+ verifier.verifyTextInLog(
+ "Found cached build, restoring
org.apache.maven.caching.test.jpms:issue-393-app from cache");
Review Comment:
This assertion hard-codes full GAV text, which can be brittle if test
project coordinates change (or if log formatting changes slightly). Consider
asserting on a more stable substring (e.g., module artifactId only) or on a
message token that is less likely to change, while still proving the restore
path was taken.
--
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]