maven icon indicating copy to clipboard operation
maven copied to clipboard

Make the Maven 4 MessageBuilderFactory available in Maven 3.9 and 3.10

Open slachiewicz opened this issue 3 weeks ago • 6 comments

Maven 3.10 added org.apache.maven.message.MessageBuilder and MessageBuilderFactory (#11874) as the replacement for maven-shared-utils' MessageUtils. Maven 4 has the same API as org.apache.maven.api.services.MessageBuilder and MessageBuilderFactory: the method sets are identical, including the default methods. They differ in the package, in where the style names live (a Constants class nested in the 3.10 MessageBuilder, org.apache.maven.api.Constants in Maven 4), and in Maven 4's factory extending Service. Maven 3.9 has neither.

So a plugin that supports more than one line cannot use either: Maven 4 ships no org.apache.maven.message, and Maven 3.9 and 3.10 ship no org.apache.maven.api.services. Such plugins stay on maven-shared-utils' MessageUtils, which works only through the JAnsi compatibility classes (apache/maven-shared-utils#452, apache/maven-surefire#3574).

Proposal: Maven 3.9 and 3.10 also ship the Maven 4 interfaces, so that one plugin binary injects org.apache.maven.api.services.MessageBuilderFactory on all three lines.

  • maven-core carries Java 8 copies of org.apache.maven.api.services.MessageBuilder and MessageBuilderFactory, org.apache.maven.api.Service, the Nonnull, Experimental and ThreadSafe annotations, and org.apache.maven.api.Constants reduced to the style names. A reduced Constants is safe: all its fields are String constants, which the compiler inlines into the calling code, so no plugin reads them from Maven's copy at run time. maven-core already exports org.apache.maven.*.
  • Maven 3.10 binds the API factory to an adapter over its existing MessageBuilderFactory, so colours and terminal detection stay as they are. This needs two fixes in 3.10 first: core exports org.apache.maven.*, which classworlds matches for that exact package only, so plugins cannot load org.apache.maven.message today (a mojo injecting it fails on 3.10.0 with NoClassDefFoundError); and JLineMessageBuilderFactory is in no Sisu index, so every injected MessageBuilderFactory is the uncoloured default.
  • Maven 3.9 binds it to an implementation over maven-shared-utils' MessageUtils (colour and terminal width) with the style resolution Maven 3.10 uses, so the API's style names (bold,f:cyan, maven.style.*) behave the same on both lines.
  • Plugin authors compile against org.apache.maven:maven-api-core 4.x in provided scope. That jar is Java 17 bytecode, but javac on JDK 17 or later reads it while compiling a plugin for --release 8.

Checked so far: a mojo built that way (JDK 21, --release 8 against maven-api-core 4.0.0-rc-7) gets the factory injected on Maven 4.0.0-rc-7 and prints the expected styles with --color=always; on Maven 3.9.16 it fails with "A required class was missing", which is the gap above.

A plugin can use the API only where Maven provides it: a mojo with a field of type org.apache.maven.api.services.MessageBuilderFactory cannot load on a Maven 3 release without these types, so a plugin adopts it together with a prerequisite on the first 3.9 and 3.10 releases that ship them.

The alternative, Maven 4 shipping org.apache.maven.message as adapters, would only cover 3.10 and 4 and would make the 3.10-only package permanent.

slachiewicz avatar Nov 09 '26 12:11 slachiewicz

Hi @slachiewicz,

I noticed that PR #13919 has been merged into "maven-3.10.x", while PR #13920 for "maven-3.9.x" was closed without merging.

I'd be interested in helping complete the Maven 3.9 backport.

Would you prefer to revive PR #13920, or would you be comfortable with me preparing a follow-up PR based on its implementation?

I also noticed a couple of potential follow-up items around Javadoc "@since" tags and "@Nonnull" annotations, which I'd be happy to address.

Thanks!

harshab054 avatar Nov 11 '26 17:11 harshab054

Why you think @harshab054 that backport is needed?

slachiewicz avatar Nov 11 '26 18:11 slachiewicz

My understanding was that the goal of #13917 was to make "org.apache.maven.api.services.MessageBuilderFactory" available to plugins across Maven 3.9, 3.10 and Maven 4.

PR #13919 addresses Maven 3.10, but the original compatibility check in the issue description showed that Maven 3.9.16 could not load a plugin compiled against this API because the required classes were missing.

I assumed the Maven 3.9 backport was still needed to achieve the stated cross-version compatibility.

Has the intended scope changed, or is supporting Maven 3.9 no longer considered necessary?

I don't want to duplicate work or pursue a backport that maintainers don't consider necessary.

harshab054 avatar Nov 12 '26 03:11 harshab054

yes, please backport https://github.com/apache/maven/pull/13919

slachiewicz avatar Nov 12 '26 18:11 slachiewicz

I opened #14008 for 3.9.x so it can make 3.9.17; it includes the @since follow-up you mentioned. Thanks for offering. A review there is welcome.

slachiewicz avatar Nov 14 '26 22:11 slachiewicz

Maven 3.10.1 ships the API (#13919). Maven 3.9.17 will ship it (#14008). A plugin that injects org.apache.maven.api.services.MessageBuilderFactory needs a prerequisite on those releases.

slachiewicz avatar Nov 21 '26 16:11 slachiewicz