Fix integration test to correctly reflect Maven 3/4 behavior
Both Maven 3 and 4 correctly fail when building projects with recursive
variable references. The key difference is in dependency consumption:
- Maven 4: Warns about invalid dependency POMs with recursive references
- Maven 3: May silently ignore the issue in dependency POMs
Updated test expectations and documentation to reflect this correct understanding.
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
index 2c5f7fe..712d5a9 100644
--- 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
@@ -27,12 +27,13 @@
/**
* 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:
+ * When a pom.xml contains a {@code <url>${project.url}</url>}, both Maven 3 and 4 fail
+ * when trying to build the project directly 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.
+ * However, the key difference is in how they handle pre-built artifacts with recursive
+ * references when consumed as dependencies. Maven 4 detects and warns about these issues
+ * in dependency POMs, while Maven 3 may silently ignore them.
*/
public class MavenITgh11074RecursiveProjectUrlTest extends AbstractMavenIntegrationTestCase {
@@ -41,40 +42,36 @@ public MavenITgh11074RecursiveProjectUrlTest() {
}
/**
- * Test that recursive project.url reference fails in Maven 4+ but was tolerated in Maven 3.
+ * Test that recursive project.url reference in a local project fails in both Maven 3 and 4.
+ * This test demonstrates that both versions correctly reject building projects with recursive references.
*
* @throws Exception in case of failure
*/
@Test
- public void testRecursiveProjectUrl() throws Exception {
+ public void testRecursiveProjectUrlInLocalProject() 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");
+ // Both Maven 3 and 4 should fail when trying to build a project with recursive reference
+ assertThrows(
+ Exception.class,
+ () -> {
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ },
+ "Both Maven 3 and 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();
- }
+ // Verify the specific error message is present
+ verifier.verifyTextInLog("recursive variable reference: project.url");
}
/**
- * 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.
+ * Test that recursive project.url reference in dependency POM produces different behavior
+ * between Maven 3 and Maven 4. This simulates the real-world scenario where problematic
+ * artifacts are already published in repositories.
*
* @throws Exception in case of failure
*/
@@ -90,18 +87,17 @@ public void testRecursiveProjectUrlInDependencyPom() throws Exception {
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();
+ // Both Maven 3 and 4 should succeed when consuming pre-built artifacts with recursive references
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
- // Verify the specific warning message is present
+ if (matchesVersionRange("[4.0.0-alpha-1,)")) {
+ // Maven 4+ should show warning about invalid dependency POM
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();
+ // Maven 3 may not detect or warn about the recursive reference
+ // This is the key difference - Maven 3 silently ignores the issue
}
}
}
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
index 64ae32d..b57634b 100644
--- 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
@@ -14,7 +14,7 @@
## Expected Behavior
-- **Maven 3**: Build succeeds, recursive reference may not be detected
+- **Maven 3**: Build succeeds, recursive reference not detected/warned about
- **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
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
index 652b41e..23172c9 100644
--- 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
@@ -17,22 +17,18 @@
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">
+<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>
-
+ <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>
@@ -50,14 +46,14 @@
<executions>
<execution>
<id>resolve-dependencies</id>
- <phase>validate</phase>
<goals>
<goal>resolve</goal>
</goals>
+ <phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
-
+
</project>
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
index f067940..998d78d 100644
--- 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
@@ -24,9 +24,11 @@
## Expected Behavior
-- **Maven 3**: Build may succeed (recursive reference not detected)
+- **Maven 3**: Build fails with "recursive variable reference: project.url" error
- **Maven 4+**: Build fails with "recursive variable reference: project.url" error
+Both versions correctly detect and reject recursive references when building projects directly.
+
## 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
index 7af43a4..ed5fc3a 100644
--- 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
@@ -17,23 +17,19 @@
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">
+<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>
-
+ <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>