You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2025/08/28 19:52:42 UTC

(maven) 01/01: Add integration test for recursive project.url variable reference (GH-11074)

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

gnodet pushed a commit to branch feature/gh-11074-recursive-project-url-it
in repository https://gitbox.apache.org/repos/asf/maven.git

commit b34c8de0add7b7bbbd57b07cbf9d646af3d0a86f
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Aug 28 21:52:26 2025 +0200

    Add integration test for recursive project.url variable reference (GH-11074)
    
    This integration test demonstrates the behavior difference between Maven 3 and Maven 4
    when handling recursive variable references in project.url.
    
    - Direct recursive reference: Maven 4 fails with 'recursive variable reference: project.url'
    - Dependency recursive reference: Maven 4 shows warning but continues build
    
    Relates to: https://github.com/apache/maven/issues/11074
---
 .../it/MavenITgh11074RecursiveProjectUrlTest.java  | 107 +++++++++++++++++++++
 .../README.md                                      |  26 +++++
 .../pom.xml                                        |  63 ++++++++++++
 .../settings-template.xml                          |  48 +++++++++
 .../gh-11074-recursive-project-url/README.md       |  32 ++++++
 .../gh-11074-recursive-project-url/pom.xml         |  39 ++++++++
 .../core-it-javaagent/dependency-reduced-pom.xml   |  53 ++++++++++
 7 files changed, 368 insertions(+)

diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11074RecursiveProjectUrlTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11074RecursiveProjectUrlTest.java
new file mode 100644
index 0000000000..2c5f7fea68
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11074RecursiveProjectUrlTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.it;
+
+import java.io.File;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * This is a test set for <a href="https://github.com/apache/maven/issues/11074">GH-11074</a>.
+ *
+ * When a pom.xml contains a {@code <url>${project.url}</url>}, it now fails with Maven 4
+ * with an error like:
+ * {@code [ERROR] recursive variable reference: project.url}
+ *
+ * This was not failing in Maven 3, but should fail in Maven 4 to prevent infinite loops
+ * during variable resolution.
+ */
+public class MavenITgh11074RecursiveProjectUrlTest extends AbstractMavenIntegrationTestCase {
+
+    public MavenITgh11074RecursiveProjectUrlTest() {
+        super("(,)"); // Test for all Maven versions to see the behavior difference
+    }
+
+    /**
+     * Test that recursive project.url reference fails in Maven 4+ but was tolerated in Maven 3.
+     *
+     * @throws Exception in case of failure
+     */
+    @Test
+    public void testRecursiveProjectUrl() throws Exception {
+        File testDir = extractResources("/gh-11074-recursive-project-url");
+
+        Verifier verifier = newVerifier(testDir.getAbsolutePath());
+        verifier.setAutoclean(false);
+        verifier.addCliArgument("validate");
+
+        if (matchesVersionRange("[4.0.0-alpha-1,)")) {
+            // Maven 4+ should fail with recursive variable reference error
+            assertThrows(
+                    Exception.class,
+                    () -> {
+                        verifier.execute();
+                        verifier.verifyErrorFreeLog();
+                    },
+                    "Maven 4+ should fail when project.url contains recursive reference");
+
+            // Verify the specific error message is present
+            verifier.verifyTextInLog("recursive variable reference: project.url");
+        } else {
+            // Maven 3 should not fail (though it may produce warnings)
+            verifier.execute();
+            verifier.verifyErrorFreeLog();
+        }
+    }
+
+    /**
+     * Test that recursive project.url reference in dependency POM produces warning in Maven 4+.
+     * The build succeeds but Maven 4+ correctly identifies and warns about the invalid POM.
+     *
+     * @throws Exception in case of failure
+     */
+    @Test
+    public void testRecursiveProjectUrlInDependencyPom() throws Exception {
+        File testDir = extractResources("/gh-11074-recursive-project-url-dependency");
+
+        Verifier verifier = newVerifier(testDir.getAbsolutePath());
+        verifier.setAutoclean(false);
+        verifier.deleteArtifacts("org.apache.maven.its.gh11074");
+        verifier.filterFile("settings-template.xml", "settings.xml");
+        verifier.addCliArgument("--settings");
+        verifier.addCliArgument("settings.xml");
+        verifier.addCliArgument("validate");
+
+        if (matchesVersionRange("[4.0.0-alpha-1,)")) {
+            // Maven 4+ should succeed but show warning about invalid dependency POM
+            verifier.execute();
+            verifier.verifyErrorFreeLog();
+
+            // Verify the specific warning message is present
+            verifier.verifyTextInLog("recursive variable reference: project.url");
+            verifier.verifyTextInLog("The POM for org.apache.maven.its.gh11074:bad-dependency:jar:1.0 is invalid");
+        } else {
+            // Maven 3 should not fail (though it may produce warnings)
+            verifier.execute();
+            verifier.verifyErrorFreeLog();
+        }
+    }
+}
diff --git a/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/README.md b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/README.md
new file mode 100644
index 0000000000..64ae32d679
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/README.md
@@ -0,0 +1,26 @@
+# GH-11074: Recursive Project URL in Dependency POM Test
+
+This integration test demonstrates how Maven 4 handles recursive variable references in dependency POMs.
+
+## Issue Description
+
+When a dependency's POM contains `<url>${project.url}</url>`, Maven 4 correctly detects this as a recursive variable reference and produces a warning while still allowing the build to continue.
+
+## Test Setup
+
+- `pom.xml`: Consumer project that depends on `bad-dependency`
+- `repo/org/apache/maven/its/mngXXXX/bad-dependency/1.0/bad-dependency-1.0.pom`: Dependency POM with recursive `project.url`
+- `settings-template.xml`: Settings to use the local test repository
+
+## Expected Behavior
+
+- **Maven 3**: Build succeeds, recursive reference may not be detected
+- **Maven 4+**: Build succeeds but shows warning:
+  ```
+  [WARNING] The POM for org.apache.maven.its.gh11074:bad-dependency:jar:1.0 is invalid, transitive dependencies (if any) will not be available: 1 problem was for org.apache.maven.its.gh11074:bad-dependency:jar:1.0
+      - [ERROR] recursive variable reference: project.url
+  ```
+
+## Real-world Impact
+
+This matches the behavior described in the original issue where dependencies like `com.slack.api:slack-api-client:jar:1.45.4` would show similar warnings in Maven 4 but not cause build failures.
diff --git a/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/pom.xml b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/pom.xml
new file mode 100644
index 0000000000..652b41e4e1
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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>org.apache.maven.its.gh11074</groupId>
+  <artifactId>consumer-project</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+  
+  <name>Test consumer project that depends on artifact with recursive project.url</name>
+  <description>
+    This project depends on an artifact whose POM contains a recursive reference to project.url.
+    This should fail in Maven 4+ when the dependency POM is processed.
+  </description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.gh11074</groupId>
+      <artifactId>bad-dependency</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>3.8.1</version>
+        <executions>
+          <execution>
+            <id>resolve-dependencies</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>resolve</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+</project>
diff --git a/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/settings-template.xml b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/settings-template.xml
new file mode 100644
index 0000000000..88d74c6259
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url-dependency/settings-template.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
+  
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <repositories>
+        <repository>
+          <id>it-repo</id>
+          <url>file://${basedir}/repo</url>
+          <releases>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+            <checksumPolicy>ignore</checksumPolicy>
+          </snapshots>
+        </repository>
+      </repositories>
+    </profile>
+  </profiles>
+  
+  <activeProfiles>
+    <activeProfile>it-repo</activeProfile>
+  </activeProfiles>
+  
+</settings>
diff --git a/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/README.md b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/README.md
new file mode 100644
index 0000000000..f067940427
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/README.md
@@ -0,0 +1,32 @@
+# GH-11074: Recursive Project URL Test
+
+This integration test demonstrates the behavior difference between Maven 3 and Maven 4 when handling recursive variable references in `project.url`.
+
+## Issue Description
+
+When a POM contains `<url>${project.url}</url>`, Maven 4 now correctly detects this as a recursive variable reference and fails with:
+
+```
+[ERROR] recursive variable reference: project.url
+```
+
+This was not detected in Maven 3, but Maven 4's improved variable resolution correctly identifies and prevents infinite loops during interpolation.
+
+## Test Case
+
+The test POM (`pom.xml`) contains:
+
+```xml
+<url>${project.url}</url>
+```
+
+This creates a recursive reference where `project.url` tries to resolve to itself.
+
+## Expected Behavior
+
+- **Maven 3**: Build may succeed (recursive reference not detected)
+- **Maven 4+**: Build fails with "recursive variable reference: project.url" error
+
+## Real-world Example
+
+This issue was observed with dependencies like `com.slack.api:slack-api-client:jar:1.45.4` which contained similar recursive references in their POMs.
diff --git a/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/pom.xml b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/pom.xml
new file mode 100644
index 0000000000..7af43a4b8d
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-11074-recursive-project-url/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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>org.apache.maven.its.gh11074</groupId>
+  <artifactId>recursive-project-url</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+  
+  <name>Test for recursive project.url reference</name>
+  <description>
+    This POM contains a recursive reference to project.url which should fail in Maven 4+
+    but was tolerated in Maven 3.
+  </description>
+  
+  <!-- This is the problematic recursive reference -->
+  <url>${project.url}</url>
+  
+</project>
diff --git a/its/core-it-support/core-it-javaagent/dependency-reduced-pom.xml b/its/core-it-support/core-it-javaagent/dependency-reduced-pom.xml
new file mode 100644
index 0000000000..e626d98b0e
--- /dev/null
+++ b/its/core-it-support/core-it-javaagent/dependency-reduced-pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <parent>
+    <artifactId>core-it-support</artifactId>
+    <groupId>org.apache.maven.its</groupId>
+    <version>2.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>core-it-javaagent</artifactId>
+  <version>2.1-SNAPSHOT</version>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Premain-Class>org.apache.maven.coreits.javaagent.mng5669.Premain</Premain-Class>
+              <Can-Retransform-Classes>true</Can-Retransform-Classes>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-shade-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <filters>
+                <filter>
+                  <artifact>org.ow2.asm:*</artifact>
+                  <excludes>
+                    <exclude>module-info.class</exclude>
+                    <exclude>META-INF/MANIFEST.MF</exclude>
+                  </excludes>
+                </filter>
+              </filters>
+              <relocations>
+                <relocation>
+                  <pattern>org.objectweb.asm</pattern>
+                  <shadedPattern>shaded.org.objectweb.asm</shadedPattern>
+                </relocation>
+              </relocations>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>