← Back to Pull requests

Read the Test Resources settings of the application mn:run selects from a reactor #1737

Open
graemerocher opened this pull request with 715 lines diff across 18 files
View on GitHub
graemerocher graemerocher commented on Oct 04, 2026 12:01 UTC
Author

Related to micronaut-projects/micronaut-core#13654. This is the mn:run counterpart of the reactor fix that #1730 makes for mn:dev and mn:test. It is independent of that stack (#1725 → #1726 → #1730), so it targets 5.1.x directly.

The problem

mn:run is an aggregator. Run from a reactor root that does not declare the plugin, it selects the one module that does, the application. Maven configures a mojo from the project the goal was invoked on, though. So every property-backed parameter was evaluated against the root, and the application's own plugin configuration was ignored:

  • An application that sets micronaut.test.resources.enabled itself ran without a Test Resources service. A root that enables it while the application disables it still started one.

  • The same went for micronaut.test.resources.shared, .namespace, .version and the other properties, and for <testResourcesDependencies> and <classpathInference> in the application's micronaut-maven-plugin configuration.

  • buildDirectory was the root's target. The service settings were written beside the root, while the launch read them from beside the application.
  • The fix

    When mn:run selects the application from the reactor, RunMojo reconfigures itself as Maven would have configured it with -pl app:

    1. It resets the goal's editable parameters to a new mojo's values, because Maven's configurator does not assign an expression that resolves to nothing. Otherwise a value resolved only in the root would remain.
    2. It takes the application's plugin-level configuration and merges the default-cli execution's configuration over it. It keeps only this goal's parameters and merges the result over the goal's own defaults and property expressions (MojoDescriptorCreator.convert).
    3. It applies the result with Maven's basic configurator. A PluginParameterExpressionEvaluator evaluates it against the application, so command-line -D properties still win.

    When the goal runs on the application itself (a single-module project, or -pl app), nothing changes.

    Tests

  • New unit test RunMojoReactorConfigurationTest covers four cases: the application enables Test Resources and the root does not; the root enables it and the application disables it; a -D on the command line still wins; a value resolved only in the root does not remain. It also checks that default-cli merges over the plugin configuration and that other goals' settings are left out.

  • New invoker IT test-resources-run-reactor has a root without Test Resources, a resolver module (a custom TestResourcesResolver, so no Docker is needed) and an app module. The app module enables Test Resources in its own properties and adds the resolver through its own <testResourcesDependencies>. Running mn:run from the root starts the service in app/target, and the application prints the property the service resolves. The service is stopped afterwards.

  • New invoker IT test-resources-run-reactor-disabled is the reverse: the root enables Test Resources and the application disables it. No service is started.

  • Both new ITs fail without the fix. multi-project, multi-project-multi-runnable, multi-project-multi-runnable-error, run and run-aot still pass. test-resources-run needs Docker, so it was not run locally.
  • Diff: 715 lines (+710 / -5) across 18 files Reviewer: graemerocher Review duration: 87299m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.96) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.96 · 715 lines diff across 18 files
    0.96
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 5 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.393
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    8 items
    graemerocher graemerocher commented on Oct 08, 2026 21:18 UTC
    Reviewer

    Reviewed as part of the combined reload-stack review for micronaut-core#13654. This pass covered selected-project configuration, parameter reset and Test Resources initialization, including interactions with the later linked changes.

    No additional actionable finding in this PR in this pass.

    This is a static/integration review, not an approval or a claim that the full JVM/native, build-tool and broker/database test matrix passed. Focused reproductions were used for the Kotlin metadata, Python imported-binding and Java compilation-retry findings elsewhere in the stack.

    alvarosanchez alvarosanchez commented on code on Nov 07, 2026 11:13 UTC
    Code Review
    micronaut-maven-plugin/src/main/java/io/micronaut/maven/RunMojo.java:1
    @@ -29,10 +29,16 @@
     import io.micronaut.testresources.buildtools.ServerSettings;
     import io.micronaut.testresources.buildtools.ServerUtils;
     import org.apache.maven.execution.MavenSession;
    +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;

    Nit: MojoDescriptorCreator lives in org.apache.maven.lifecycle.internal, so this relies on internal Maven API that may move or change on Maven 4. Building the defaults Xpp3Dom from descriptor.getParameters() (name + getDefaultValue()/getExpression()) would avoid it.

    ---
    _Generated by Claude Code_

    alvarosanchez alvarosanchez commented on code on Nov 07, 2026 11:13 UTC
    Code Review
    micronaut-maven-plugin/src/main/java/io/micronaut/maven/RunMojo.java:1
    @@ -371,6 +392,117 @@ protected final void initialize() {
             compileProject();
         }
     
    +    /**
    +     * Configures this goal as the selected application declares it. Maven configured the mojo from the project the
    +     * goal was invoked on, the reactor root when {@code mn:run} runs from an aggregator that does not declare the
    +     * plugin, so a property-backed parameter, such as {@code micronaut.test.resources.enabled}, and the plugin's
    +     * configuration, such as {@code testResourcesDependencies}, came from the root. Here the application's
    +     * plugin-level {@code micronaut-maven-plugin} configuration, with its {@code default-cli} execution's merged over
    +     * it, restricted to this goal's parameters and merged over the goal's defaults and property expressions, is applied
    +     * with Maven's configurator and evaluated against the application, as Maven would have done had the goal run on it.
    +     */
    +    private void applyRunnableProjectConfiguration() {
    +        if (mojoExecution == null || configurator == null) {
    +            return;
    +        }
    +        MojoDescriptor descriptor = mojoExecution.getMojoDescriptor();
    +        Xpp3Dom configuration = Xpp3Dom.mergeXpp3Dom(runnableProjectConfiguration(runnableProject, descriptor),
    +            MojoDescriptorCreator.convert(descriptor));
    +        resetParameters(descriptor);
    +        MavenSession runnableSession = mavenSession.clone();
    +        runnableSession.setCurrentProject(runnableProject);
    +        var evaluator = new PluginParameterExpressionEvaluator(runnableSession, mojoExecution);
    +        try {
    +            ClassRealm realm = descriptor.getPluginDescriptor().getClassRealm();
    +            configurator.configureComponent(this, new XmlPlexusConfiguration(configuration), evaluator, realm);
    +        } catch (ComponentConfigurationException e) {
    +            throw new IllegalStateException("Cannot apply the micronaut-maven-plugin configuration of " + runnableProject.getArtifactId() + ": " + e.getMessage(), e);
    +        }
    +    }
    +
    +    /**
    +     * Resets the goal's parameters to the values a new mojo starts with, so that a value Maven resolved against the
    +     * reactor root, which the application's configuration leaves unresolved, does not remain: Maven's configurator
    +     * does not assign an expression that resolves to nothing.
    +     *
    +     * @param descriptor the goal's descriptor
    +     */
    +    private void resetParameters(MojoDescriptor descriptor) {
    +        if (descriptor.getParameters() == null) {
    +            return;
    +        }
    +        var pristine = new RunMojo(mavenSession, null, projectBuilder, toolchainManager, compilerService,

    Nit: constructing a throwaway RunMojo to read field initialiser defaults works, but the constructor also runs findJavaExecutable(toolchainManager, mavenSession) again. Not a problem today, just heavier than it looks; worth a comment, or a small factory that skips that lookup.

    ---
    _Generated by Claude Code_

    alvarosanchez alvarosanchez commented on Nov 07, 2026 11:13 UTC
    Reviewer

    Looks good to me. This fixes a real problem: from an aggregator root, mn:run took the plugin configuration and the micronaut.test.resources.* properties from the root rather than from the selected application. Resetting the parameters before applying the application's configuration (the second commit) is the right call, and the unit tests plus the two ITs cover it well. Two non-blocking nits inline.

    One cross-PR note: DevMojo in #1725 copies this "apply the selected application's configuration" logic but not the parameter reset, so it has the stale-root-value bug this PR fixes. It'd be worth extracting this into a shared helper both mojos use.

    ---
    _Generated by Claude Code_

    graemerocher graemerocher commented on code on Dec 03, 2026 20:52 UTC
    Code Review
    micronaut-maven-plugin/src/main/java/io/micronaut/maven/RunMojo.java:1
    @@ -29,10 +29,16 @@
     import io.micronaut.testresources.buildtools.ServerSettings;
     import io.micronaut.testresources.buildtools.ServerUtils;
     import org.apache.maven.execution.MavenSession;
    +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;

    Done in a43a384d9: the default configuration is now built from MojoDescriptor.getMojoConfiguration() (each parameter's expression and default-value), as MojoDescriptorCreator.convert did, so RunMojo no longer imports anything from org.apache.maven.lifecycle.internal.

    _🤖 Addressed by Claude Code_

    graemerocher graemerocher commented on code on Dec 03, 2026 20:52 UTC
    Code Review
    micronaut-maven-plugin/src/main/java/io/micronaut/maven/RunMojo.java:1
    @@ -371,6 +392,117 @@ protected final void initialize() {
             compileProject();
         }
     
    +    /**
    +     * Configures this goal as the selected application declares it. Maven configured the mojo from the project the
    +     * goal was invoked on, the reactor root when {@code mn:run} runs from an aggregator that does not declare the
    +     * plugin, so a property-backed parameter, such as {@code micronaut.test.resources.enabled}, and the plugin's
    +     * configuration, such as {@code testResourcesDependencies}, came from the root. Here the application's
    +     * plugin-level {@code micronaut-maven-plugin} configuration, with its {@code default-cli} execution's merged over
    +     * it, restricted to this goal's parameters and merged over the goal's defaults and property expressions, is applied
    +     * with Maven's configurator and evaluated against the application, as Maven would have done had the goal run on it.
    +     */
    +    private void applyRunnableProjectConfiguration() {
    +        if (mojoExecution == null || configurator == null) {
    +            return;
    +        }
    +        MojoDescriptor descriptor = mojoExecution.getMojoDescriptor();
    +        Xpp3Dom configuration = Xpp3Dom.mergeXpp3Dom(runnableProjectConfiguration(runnableProject, descriptor),
    +            MojoDescriptorCreator.convert(descriptor));
    +        resetParameters(descriptor);
    +        MavenSession runnableSession = mavenSession.clone();
    +        runnableSession.setCurrentProject(runnableProject);
    +        var evaluator = new PluginParameterExpressionEvaluator(runnableSession, mojoExecution);
    +        try {
    +            ClassRealm realm = descriptor.getPluginDescriptor().getClassRealm();
    +            configurator.configureComponent(this, new XmlPlexusConfiguration(configuration), evaluator, realm);
    +        } catch (ComponentConfigurationException e) {
    +            throw new IllegalStateException("Cannot apply the micronaut-maven-plugin configuration of " + runnableProject.getArtifactId() + ": " + e.getMessage(), e);
    +        }
    +    }
    +
    +    /**
    +     * Resets the goal's parameters to the values a new mojo starts with, so that a value Maven resolved against the
    +     * reactor root, which the application's configuration leaves unresolved, does not remain: Maven's configurator
    +     * does not assign an expression that resolves to nothing.
    +     *
    +     * @param descriptor the goal's descriptor
    +     */
    +    private void resetParameters(MojoDescriptor descriptor) {
    +        if (descriptor.getParameters() == null) {
    +            return;
    +        }
    +        var pristine = new RunMojo(mavenSession, null, projectBuilder, toolchainManager, compilerService,

    Added a comment in a43a384d9 where the throwaway mojo is built: its constructor looks the Java executable up again through the toolchain, a small cost once per run that changes nothing in the reset.

    _🤖 Addressed by Claude Code_

    Reviewers
    Assignees
    graemerocher graemerocher
    Labels
    risk: low confidence: 81.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 96% (HIGH) · Higher = larger blast radius
    96%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.7% · Lower = rushed or shallow review
    81.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.5% · Safe to merge
    17.5%