Make the Maven 4 MessageBuilderFactory available in Maven 3.9 and 3.10
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-corecarries Java 8 copies oforg.apache.maven.api.services.MessageBuilderandMessageBuilderFactory,org.apache.maven.api.Service, theNonnull,ExperimentalandThreadSafeannotations, andorg.apache.maven.api.Constantsreduced to the style names. A reducedConstantsis safe: all its fields areStringconstants, which the compiler inlines into the calling code, so no plugin reads them from Maven's copy at run time.maven-corealready exportsorg.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 exportsorg.apache.maven.*, which classworlds matches for that exact package only, so plugins cannot loadorg.apache.maven.messagetoday (a mojo injecting it fails on 3.10.0 withNoClassDefFoundError); andJLineMessageBuilderFactoryis in no Sisu index, so every injectedMessageBuilderFactoryis 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-core4.x inprovidedscope. 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.
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!
Why you think @harshab054 that backport is needed?
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.
yes, please backport https://github.com/apache/maven/pull/13919
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.
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.