Skip to content
/ maven Public
forked from apache/maven

Restore missing deprecated constants and extension model classes in MavenCli for backward compatibility#2

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-missing-code-restoration
Closed

Restore missing deprecated constants and extension model classes in MavenCli for backward compatibility#2
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-missing-code-restoration

Conversation

Copy link

Copilot AI commented Oct 20, 2025

Description

Fixes apache#11300 by restoring missing public static constants and extension model classes in the MavenCli class that were present in Maven 3.x but are missing in the Maven 4 compatibility layer.

Changes

Constants Restored

This PR adds the following deprecated constants to org.apache.maven.cli.MavenCli to maintain backward compatibility with existing code that depends on the Maven 3.x embedder API:

  • LOCAL_REPO_PROPERTY - String constant for "maven.repo.local" property
  • USER_HOME - System property for user home directory
  • USER_MAVEN_CONFIGURATION_HOME - Reference to the .m2 directory
  • STYLE_COLOR_PROPERTY - String constant for "style.color" property

All constants are marked with @Deprecated and include Javadoc pointing to the equivalent constants in the new org.apache.maven.api.Constants class.

Extension Model Classes Restored

This PR also restores the extension model classes that were previously generated from the MDO file in Maven 3.9.x:

  • org.apache.maven.cli.internal.extension.model.CoreExtension - Deprecated model class representing a build extension
  • org.apache.maven.cli.internal.extension.model.CoreExtensions - Deprecated model class representing a collection of extensions

ExtensionResolutionException API Fix

Updated org.apache.maven.cli.internal.ExtensionResolutionException to maintain backward compatibility:

  • Changed getExtension() return type from org.apache.maven.api.cli.extensions.CoreExtension (new API) to org.apache.maven.cli.internal.extension.model.CoreExtension (Maven 3.x API)
  • Added overloaded constructor accepting the new API type, which internally converts to the old type
  • Ensures existing code using the Maven 3.x embedder API continues to work

Rationale

The MavenCli class is already deprecated but serves as a compatibility layer for projects migrating from Maven 3.x to Maven 4. These constants and model classes were commonly used in embedder applications and their absence breaks backward compatibility unnecessarily. By restoring them with proper deprecation annotations, we:

  1. Allow existing code to continue working without changes
  2. Provide clear migration path via deprecation warnings and Javadoc
  3. Maintain API consistency with Maven 3.x embedder
  4. Fix incompatible return type changes that would break existing code

Extension Classes

The org.apache.maven.cli.internal package contains the necessary extension-related classes:

  • BootstrapCoreExtensionManager (deprecated)
  • ExtensionResolutionException (deprecated, now with backward-compatible API)
  • New org.apache.maven.cli.internal.extension.model package with CoreExtension and CoreExtensions classes

Testing

  • All existing tests pass (81 tests, 1 skipped)
  • Build completes successfully with no errors
  • No security issues detected by CodeQL

As per the issue description, no new tests were added - this change only restores missing API elements.

Original prompt

Fix @apache/mavenapache/issues/11300

but we need no tests for this, just restore the missing code and possibly depreacte it with @deprecated


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing code restoration without tests Restore missing deprecated constants in MavenCli for backward compatibility Oct 20, 2025
Copilot AI requested a review from laeubi October 20, 2025 09:58
@laeubi
Copy link
Owner

laeubi commented Oct 20, 2025

@copilot the internal classes are there, but if you look here:

https://github.com/laeubi/maven/tree/maven-3.9.x/maven-embedder/src/main/mdo

there are some classes that are generated:

<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<configuration>
<version>1.1.0</version>
<models>
<model>src/main/mdo/core-extensions.mdo</model>
</models>
</configuration>
</plugin>

these are now missing in Maven 4 and also the return type has changed in an incompatible way:

- Created org.apache.maven.cli.internal.extension.model package
- Added CoreExtension and CoreExtensions classes (deprecated)
- Updated ExtensionResolutionException to return old model type
- Added overloaded constructor for compatibility with new API

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 20, 2025

@copilot the internal classes are there, but if you look here:

https://github.com/laeubi/maven/tree/maven-3.9.x/maven-embedder/src/main/mdo
...

Added the missing extension model classes in commit 9bf6ab5:

  • Created org.apache.maven.cli.internal.extension.model.CoreExtension (deprecated)
  • Created org.apache.maven.cli.internal.extension.model.CoreExtensions (deprecated)
  • Updated ExtensionResolutionException.getExtension() to return the old model type org.apache.maven.cli.internal.extension.model.CoreExtension
  • Added overloaded constructor to support both old and new API types internally

The classes match the structure that would have been generated from the Maven 3.9.x MDO file. All tests pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • foo.bar
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx256m -jar /home/REDACTED/work/maven/maven/compat/maven-compat/target/surefire/surefirebooter-20251020102223703_127.jar /home/REDACTED/work/maven/maven/compat/maven-compat/target/surefire 2025-10-20T10-20-54_842-jvmRun1 surefire-20251020102223703_125tmp surefire_18-20251020102223703_126tmp (dns block)
  • repository.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx256m -jar /home/REDACTED/work/maven/maven/impl/maven-impl/target/surefire/surefirebooter-20251020102118037_21.jar /home/REDACTED/work/maven/maven/impl/maven-impl/target/surefire 2025-10-20T10-20-54_842-jvmRun1 surefire-20251020102118037_19tmp surefire_6-20251020102118037_20tmp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Restore missing deprecated constants in MavenCli for backward compatibility Restore missing deprecated constants and extension model classes in MavenCli for backward compatibility Oct 20, 2025
@gnodet
Copy link

gnodet commented Oct 23, 2025

@laeubi LGTM, but the PR should be moved to apache/maven instead.
And I think you said it was also missing the old xpp3 reader at least.

@laeubi
Copy link
Owner

laeubi commented Oct 23, 2025

Yeah I'm not 100% sure about this should I proceed on this? Especially as it now references the new API in maven4 maybe it should just be the case?

@gnodet
Copy link

gnodet commented Oct 23, 2025

Yeah I'm not 100% sure about this should I proceed on this? Especially as it now references the new API in maven4 maybe it should just be the case?

Yes, I've seen the switch in the exception, I think it's fine. It's also fine to not try to generate the two classes CoreExtension and CoreExtensions. I've also added the xpp3 reader/writer.

See apache#11320

@laeubi
Copy link
Owner

laeubi commented Oct 24, 2025

Yeah I'm not 100% sure about this should I proceed on this? Especially as it now references the new API in maven4 maybe it should just be the case?

Yes, I've seen the switch in the exception, I think it's fine. It's also fine to not try to generate the two classes CoreExtension and CoreExtensions. I've also added the xpp3 reader/writer.

See apache#11320

Many thanks!

Closing as replaced by

@laeubi laeubi closed this Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[back compat] some constants and code is missing from maven-embedder

3 participants