Skip to content
Closed
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
@@ -0,0 +1,74 @@
# Hello Maven 4 Test Project

## Overview
This is a demonstration project showcasing Maven 4 features for testing m2e compatibility.
The project is based on real-world usage patterns from [jline3](https://github.com/jline/jline3).

## Project Structure
```
HelloMaven4/
├── pom.xml (parent)
├── hello-core/ (library subproject)
│ └── src/main/java/org/eclipse/m2e/tests/demo/core/
│ └── GreetingService.java
└── hello-app/ (application subproject)
└── src/main/java/org/eclipse/m2e/tests/demo/app/
└── HelloWorldApp.java
```

## Maven 4 Features Used

This project demonstrates the following Maven 4 features from [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html):

### 1. ✅ New Model Version 4.1.0
- **Feature**: Maven 4 introduces a new POM model version `4.1.0`
- **Usage**: All POMs use `<modelVersion>4.1.0</modelVersion>` and `xmlns="http://maven.apache.org/POM/4.1.0"` namespace
- **Location**: All `pom.xml` files
- **Status**: Demonstrated

### 2. ✅ Subprojects Instead of Modules
- **Feature**: Maven 4 uses `<subprojects>` instead of `<modules>` for better semantics
- **Usage**: Parent POM uses `<subprojects>` to declare child projects
- **Location**: `pom.xml` (parent)
- **Status**: Demonstrated

### 3. ✅ Inheritance of GroupId and Version
- **Feature**: Child projects can omit `<groupId>` and `<version>` when inheriting from parent
- **Usage**: Child POMs (`hello-core` and `hello-app`) omit these elements
- **Location**: `hello-core/pom.xml` and `hello-app/pom.xml`
- **Status**: Demonstrated

### 4. ⏳ Build/Consumer POM Split
- **Feature**: Maven 4 separates build-time and consumption-time concerns
- **Usage**: Not explicitly demonstrated in this simple project
- **Status**: Not applicable for this simple test case

### 5. ⏳ Better Java Version Handling
- **Feature**: Improved handling of Java versions with `maven.compiler.release`
- **Usage**: Uses `maven.compiler.release` property set to 11
- **Location**: Parent POM properties
- **Status**: Partially demonstrated

## Testing with Maven 4

This project is designed to be built with **Maven 4.0.0-rc-2** or later (Preview release).

To verify Maven 4 compatibility:
```bash
# Requires Maven 4.0.0-rc-2 or later
mvn clean install
```

## Purpose

This test project serves two main goals:

1. **Demonstrate Incompatibility**: Show that current m2e does NOT support Maven 4 features
2. **Validation Target**: Provide a test case to verify Maven 4 support as it's implemented

## References

- [Apache Maven 4 Downloads](https://maven.apache.org/download.cgi)
- [What's New in Maven 4](https://maven.apache.org/whatsnewinmaven4.html)
- [JLine3 Project](https://github.com/jline/jline3) - Real-world Maven 4 usage example
- [Maven 4 Announcement](https://lists.apache.org/thread/jnb3snhdm4b564gz8hbctp9rfk8fc67n)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Maven 4 Subproject - demonstrates dependency on sibling subproject

This module also inherits groupId and version from parent
-->
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">

<modelVersion>4.1.0</modelVersion>

<parent>
<groupId>org.eclipse.m2e.tests.demo</groupId>
<artifactId>hello-maven4-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>hello-app</artifactId>

<name>Hello Maven 4 App</name>
<description>Application module demonstrating Maven 4 features</description>

<dependencies>
<dependency>
<groupId>org.eclipse.m2e.tests.demo</groupId>
<artifactId>hello-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.m2e.tests.demo.app;

import org.eclipse.m2e.tests.demo.core.GreetingService;

/**
* Simple HelloWorld application demonstrating Maven 4 multi-subproject structure.
*/
public class HelloWorldApp {

public static void main(String[] args) {
GreetingService service = new GreetingService();

String name = args.length > 0 ? args[0] : "Maven 4 World";
String greeting = service.greet(name);

System.out.println(greeting);
System.out.println("Built with Maven 4!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Maven 4 Subproject - demonstrates inheritance of groupId and version

Note: In Maven 4, child projects can omit groupId and version
when they inherit from parent, making the POM cleaner
-->
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">

<modelVersion>4.1.0</modelVersion>

<parent>
<groupId>org.eclipse.m2e.tests.demo</groupId>
<artifactId>hello-maven4-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>hello-core</artifactId>

<name>Hello Maven 4 Core</name>
<description>Core library module demonstrating Maven 4 features</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.eclipse.m2e.tests.demo.core;

/**
* A simple greeting service to demonstrate Maven 4 project structure.
*/
public class GreetingService {

private final String prefix;

public GreetingService(String prefix) {
this.prefix = prefix;
}

public GreetingService() {
this("Hello");
}

public String greet(String name) {
return prefix + ", " + name + "!";
}

public String getPrefix() {
return prefix;
}
}
50 changes: 50 additions & 0 deletions org.eclipse.m2e.core.tests/resources/projects/HelloMaven4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Maven 4 Test Project for m2e

This project demonstrates Maven 4 features including:
- Model version 4.1.0
- Subprojects instead of modules
- Inheritance of groupId and version from parent
-->
<project xmlns="http://maven.apache.org/POM/4.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd">

<modelVersion>4.1.0</modelVersion>

<groupId>org.eclipse.m2e.tests.demo</groupId>
<artifactId>hello-maven4-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Hello Maven 4 Parent</name>
<description>A simple Maven 4 demo project for testing m2e support</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<subprojects>
<subproject>hello-core</subproject>
<subproject>hello-app</subproject>
</subprojects>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
136 changes: 136 additions & 0 deletions org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (c) 2025 Red Hat Inc. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/

package org.eclipse.m2e.core;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.junit.After;
import org.junit.Test;

/**
* Test case for Maven 4 support in m2e.
*
* This test demonstrates that m2e currently does NOT support Maven 4 features.
* As Maven 4 support is implemented, this test can be enhanced to verify:
* - Model version 4.1.0 parsing
* - Subprojects support (instead of modules)
* - Inheritance of groupId and version
* - Build/Consumer POM split
*
* Based on real-world usage from https://github.com/jline/jline3
*
* @see https://maven.apache.org/whatsnewinmaven4.html
*/
public class Maven4Test extends AbstractMavenProjectTestCase {

Check warning on line 43 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The type 'AbstractMavenProjectTestCase' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_copilot_add-maven4-test-case/org.eclipse.m2e.tests.common/target/classes')

@After
public void clearWorkspace() throws Exception {
for(IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
p.delete(true, null);
}
}

/**
* Test Maven 4 project with model version 4.1.0 and subprojects.
*
* This test attempts to import a Maven 4 project that uses:
* - Model version 4.1.0
* - Subprojects instead of modules
* - Inheritance of groupId and version from parent
*
* Expected behavior:
* - With current m2e (Maven 3 only): This test is expected to fail or show errors
* - With Maven 4 support: This test should pass and projects should be imported correctly
*/
@Test
public void testMaven4BasicProject() throws Exception {
// Get the Maven 4 test project
File sourceDirectory = new File(
FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI());

assertNotNull("HelloMaven4 project directory should exist", sourceDirectory);
assertTrue("HelloMaven4 project directory should be a directory", sourceDirectory.isDirectory());

File parentPom = new File(sourceDirectory, "pom.xml");
assertTrue("Parent pom.xml should exist", parentPom.exists());

// Attempt to import the Maven 4 project
// Note: This will likely fail with current m2e since it doesn't support Maven 4
try {
IProject project = importProject("resources/projects/HelloMaven4/pom.xml");

Check warning on line 79 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'AbstractMavenProjectTestCase.importProject(String)' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_copilot_add-maven4-test-case/org.eclipse.m2e.tests.common/target/classes')

// If we get here, the project was imported (unexpected with current m2e)
assertNotNull("Parent project should be imported", project);

// Check if subprojects are recognized
// Note: With Maven 4 support, these should be imported as child projects
IProject helloCore = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-core");
IProject helloApp = ResourcesPlugin.getWorkspace().getRoot().getProject("hello-app");

// These assertions will help verify Maven 4 support when implemented
// For now, they document what should work with Maven 4
assertNotNull("hello-core subproject should be recognized", helloCore);
assertNotNull("hello-app subproject should be recognized", helloApp);

} catch (Exception e) {
// Expected with current m2e - Maven 4 is not yet supported
// This documents that m2e needs Maven 4 support
System.err.println("Expected failure with Maven 3 based m2e: " + e.getMessage());

// For now, we'll let this exception indicate Maven 4 is not supported
// When Maven 4 support is added, this test should pass without exceptions
fail("Maven 4 project import failed (expected with current m2e): " + e.getMessage());
}
}

/**
* Test that Maven 4 model version 4.1.0 is recognized.
*
* This is a more basic test that just checks if the model version is parsed correctly.
* When Maven 4 support is added, this should pass.
*/
@Test
public void testMaven4ModelVersion() throws Exception {
File sourceDirectory = new File(
FileLocator.toFileURL(getClass().getResource("/resources/projects/HelloMaven4")).toURI());
File parentPom = new File(sourceDirectory, "pom.xml");

assertTrue("Parent pom.xml should exist", parentPom.exists());

// Try to read the POM
// With Maven 4 support, this should recognize the 4.1.0 model version
try {
// This will likely fail with current Maven 3 based implementation
// as it doesn't recognize model version 4.1.0
@SuppressWarnings("unused")
IProject project = importProject("resources/projects/HelloMaven4/pom.xml");

Check warning on line 125 in org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/Maven4Test.java

View check run for this annotation

Jenkins - M2E / Compiler

Restriction

NORMAL: Discouraged access: The method 'AbstractMavenProjectTestCase.importProject(String)' is not API (restriction on classpath entry '/home/jenkins/agent/workspace/m2e_copilot_add-maven4-test-case/org.eclipse.m2e.tests.common/target/classes')

// If we get here, Maven 4 model version was recognized
// This indicates Maven 4 support is working

} catch (Exception e) {
// Expected with current m2e
System.err.println("Maven 4 model version not supported yet: " + e.getMessage());
fail("Maven 4 model version 4.1.0 is not supported (expected with current m2e): " + e.getMessage());
}
}
}
Loading