Skip to content

Make liberty-maven-plugin toolchain-aware (add support for Maven Toolchains) #1932

@rslemos

Description

@rslemos

Feature request: Make liberty-maven-plugin toolchain-aware

Context

When using the maven-toolchains-plugin,
Maven selects a specific JDK based on the configured toolchains and stores it in the build context
(via ToolchainManagerPrivate.storeToolchainToBuildContext).
Other plugins (like maven-compiler-plugin, maven-surefire-plugin, etc.) can then retrieve the
active toolchain with ToolchainManager.getToolchainFromBuildContext(...) and use the JDK selected
by the user, instead of relying on the JDK that runs Maven itself.

Current behavior

The Liberty Maven Plugin currently ignores toolchains.
It by default uses the JDK from the environment that runs Maven, even when a specific toolchain is configured.
Possibly workaround is by means of env.JAVA_HOME, but that duplicates what toolchain plugin is for.

Expected behavior

The plugin should honor the active toolchain and use the JDK selected by Maven Toolchains.
This would allow consistent builds when multiple JDKs are installed and toolchains are configured
(e.g., building a Liberty app on Java 8 even if Maven is running on Java 17).

Proposed implementation

The plugin could retrieve the configured toolchain early during execution, for example:

    @Component
    private ToolchainManager toolchainManager;
 
    @Component
    private MavenSession session;

    public void execute() throws MojoExecutionException {
        Toolchain tc = toolchainManager.getToolchainFromBuildContext("jdk", session);

        if (tc != null) { [...] }
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions