Skip to content

[maven-3.10.x] Replace the 3.10 MessageBuilderFactory with the Maven 4 API - #13919

Merged
slachiewicz merged 2 commits into
apache:maven-3.10.xfrom
slachiewicz:api-message-builder-factory-310
Nov 10, 2026
Merged

slachiewicz merged 2 commits into
apache:maven-3.10.xfrom
slachiewicz:api-message-builder-factory-310

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Plugins compiled against maven-api-core 4.x can inject org.apache.maven.api.services.MessageBuilderFactory on Maven 3.10 as they do on Maven 4, as proposed in #13917.

  • The 3.10 org.apache.maven.message.MessageBuilder and MessageBuilderFactory are replaced by Java 8 copies of the Maven 4 interfaces, which Maven itself now uses. The 3.10 types were never usable by plugins: core exports org.apache.maven.*, which classworlds matches for that exact package only, so a mojo injecting them failed with NoClassDefFoundError. The two interfaces are identical apart from the package, @Nonnull and extends Service. Code that embeds maven-core and used them directly changes the import.
  • maven-core also carries Service (the factory's supertype, so the copied hierarchy matches Maven 4), the Nonnull, Experimental and ThreadSafe annotations, and org.apache.maven.api.Constants reduced to the style names. All of its fields are String constants, which callers inline, so plugins compiled against the full class never read the missing ones.
  • Core exports exactly org.apache.maven.api.*, org.apache.maven.api.annotations.* and org.apache.maven.api.services.*. A plugin that bundles other maven-api-* classes keeps loading them from its own jar.
  • JLineMessageBuilderFactory was in no Sisu index, so every injection got DefaultMessageBuilderFactory, which never colours. maven-jline now generates its index, and its @Priority(10) factory wins.

Behaviour change: Maven's own messages built through the injected factory (MojoExecutor, LifecycleDependencyResolver, DeprecatedPluginValidator, DefaultMojoExecutionConfigurator, LifecycleExecutionException) are now coloured on a terminal, like the rest of the output; with -B, -l, --color=never or piped output they stay plain.

Verified: mvn verify -pl maven-core,maven-jline,maven-embedder → 430, 10 and 55 tests pass; one mojo binary compiled with --release 8 against maven-api-core 4.0.0-rc-7 gets JLineMessageBuilderFactory on the built distribution and on Maven 4.0.0-rc-7 and prints identical output on both, coloured under --color=always and a pseudo-terminal, plain when piped or with -B; javadoc on the copied sources reports no errors.

Supersedes #13918.

@slachiewicz slachiewicz added enhancement New feature or request mvn3 labels Nov 9, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review November 9, 2026 15:34
@slachiewicz slachiewicz added this to the 3.10.1 milestone Nov 9, 2026
org.apache.maven.message.MessageBuilderFactory was never visible to
plugins: core exports org.apache.maven.* only for that exact package.
Rather than export it, maven-core now carries Java 8 copies of
org.apache.maven.api.services.MessageBuilder and MessageBuilderFactory
from maven-api-core, with the annotations they use and Constants
reduced to the style names, and Maven uses those itself. A plugin
compiled against maven-api-core 4.x injects the same factory on 3.10
as on Maven 4.

maven-jline now generates its Sisu index, so the JLine factory wins
over the uncoloured default for every injection, Maven's own included.

See apache#13917.
@slachiewicz
slachiewicz force-pushed the api-message-builder-factory-310 branch from 9731ca4 to cc9a4e4 Compare November 9, 2026 17:29
@slachiewicz slachiewicz changed the title [maven-3.10.x] Provide the Maven 4 MessageBuilderFactory to plugins [maven-3.10.x] Replace the 3.10 MessageBuilderFactory with the Maven 4 API Nov 9, 2026
@slachiewicz slachiewicz added the bug Something isn't working label Nov 9, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-structured backport of the Maven 4 MessageBuilderFactory API to Maven 3.10.x. The Sisu index fix for maven-jline is the key correctness improvement — without it, sisu-maven-plugin consumers couldn't discover the new service. Package rename from org.apache.maven.message to org.apache.maven.api.services is binary-incompatible but defensible since the old package was never accessible to plugins through classworlds. Two minor documentation items below, plus an incomplete @Nonnull annotation pass.

Question: Is the binary-incompatible package rename from org.apache.maven.message to org.apache.maven.api.services acceptable on the 3.10.x maintenance branch? The old classes were internal (not in classworlds exports), but the rename may affect consumers using maven-core directly on the classpath. Worth explicitly addressing in the PR description.

Question: maven-jline/src/main/resources/META-INF/sisu/javax.inject.Named now exports DefaultMessageBuilderFactory — is this the right format for the Sisu index? Maven 4 uses javax.inject.Named entries for Sisu DI discovery. This looks correct, but deserves explicit confirmation that the entry format matches what sisu-maven-plugin expects for 3.10.x.

Note — @Nonnull on abstract methods: This PR adds @Nonnull to the default/concrete methods in MessageBuilder, but the three abstract methods style(String), resetStyle(), and setLength(int) are still missing the annotation. Since the goal is consistent null-safety, these should be annotated as well (even though they weren't modified by this PR, it's the same pattern applied incompletely).

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@slachiewicz

Copy link
Copy Markdown
Member Author

On the package move: org.apache.maven.message came with 3.10.0 and was never visible to plugins (the org.apache.maven.* export covers only that package), so only code embedding maven-core directly is affected; the PR description now says so.

On the index: maven-jline's META-INF/sisu/javax.inject.Named is generated by sisu-maven-plugin, the same as in the other 3.10 modules, and lists JLineMessageBuilderFactory, not DefaultMessageBuilderFactory.

On @Nonnull: the copies match maven-4.0.x exactly, where style, resetStyle and setLength carry no @Nonnull, so that change belongs in the Maven 4 API first.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — all 3 previous findings have been addressed in this update:

  • @since 3.10.1 on MessageBuilder.java — ✅ addressed (changed from 3.10.0)
  • @since 3.10.1 on MessageBuilderFactory.java — ✅ addressed (changed from 3.10.0)
  • Class-level @since 3.10.1 on Constants.java — ✅ addressed

The rest of the changes look solid:

  • The classworlds export entries (org.apache.maven.api.*, org.apache.maven.api.annotations.*, org.apache.maven.api.services.*) correctly make the new API types visible to plugins — the existing org.apache.maven.* wildcard does not recursively cover subpackages in this format, so the explicit entries are necessary.
  • The sisu-maven-plugin addition to maven-jline/pom.xml is the right fix for JLineMessageBuilderFactory being bypassed at injection time.
  • The DefaultMessageBuilderFactoryTest correctly validates the API surface under @PlexusTest (no JLine context), and the setLength(0) call is defined on the interface.
  • One note for downstream embedders: org.apache.maven.message.MessageBuilder and org.apache.maven.message.MessageBuilderFactory no longer exist in 3.10.1 (they moved to org.apache.maven.api.services.*). The PR body already documents this migration requirement. No further action needed here — just flagging it for the release notes.

LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@slachiewicz slachiewicz self-assigned this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request mvn3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants