diff --git a/native-maven-plugin/docs/functional/configuration-model.md b/native-maven-plugin/docs/functional/configuration-model.md index c67e714582..8e63a55c42 100644 --- a/native-maven-plugin/docs/functional/configuration-model.md +++ b/native-maven-plugin/docs/functional/configuration-model.md @@ -42,3 +42,10 @@ when no explicit configuration is present. The exception is a parameter intentio let the property win for one run, such as the agent toggle in [§FS-tracing-agent.1](tracing-agent.md#1-agent-enablement) where `-Dagent=false` disables an agent enabled in the POM. This is the Maven adaptation of [§root/FS-option-precedence](../../../docs/spec/functional/option-precedence.md#fs-option-precedence-command-line-input-and-durable-configuration-produce-one-option-state). + +## 6. Plugin-wide goal skipping + +Setting `true` in the native Maven plugin's root `` must skip every +plugin goal before it resolves dependencies, downloads metadata, generates files, or otherwise +causes a goal-specific side effect. When it is absent or false, each goal retains its existing +specialized skip controls and behavior. diff --git a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/MetadataRepositoryFunctionalTest.groovy b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/MetadataRepositoryFunctionalTest.groovy index f851e84e50..0c0c2f5b17 100644 --- a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/MetadataRepositoryFunctionalTest.groovy +++ b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/MetadataRepositoryFunctionalTest.groovy @@ -206,4 +206,23 @@ class MetadataRepositoryFunctionalTest extends AbstractGraalVMMavenFunctionalTes } ]''') } + + // Plugin-level skip prevents add-reachability-metadata side effects. §FS-config-model.6, §E2E-functional-tests.3.2. + void "plugin-level skip prevents reachability metadata download and copy"() { + given: + withSample("native-config-integration") + def pom = file("pom.xml") + pom.text = pom.text.replaceFirst(/(?s)(addMetadataHints<\/id>.*?)/, + '$1\n true') + + when: + mvn '-PaddMetadataHints', 'package' + + then: + buildSucceeded + outputContains "Skipping native Maven plugin goal (parameter 'skip' is true)." + outputDoesNotContain "Downloaded GraalVM reachability metadata repository" + !file("target/graalvm-reachability-metadata").exists() + !file("target/classes/META-INF/native-image/org.graalvm.internal/library-with-reflection/1.5/reflect-config.json").exists() + } } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java index f2e3e0ea9f..2a6014fb54 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeMojo.java @@ -43,7 +43,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugins.annotations.Component; @@ -87,7 +86,7 @@ /** * @author Sebastien Deleuze */ -public abstract class AbstractNativeMojo extends AbstractMojo { +public abstract class AbstractNativeMojo extends AbstractSkippableMojo { private static final String GROUP_ID = "org.graalvm.buildtools"; private static final String GRAALVM_REACHABILITY_METADATA_ARTIFACT_ID = "graalvm-reachability-metadata"; private static final String REPOSITORY_FORMAT = "zip"; diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractResourceConfigMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractResourceConfigMojo.java index 83f2b9b06d..aab317fb0b 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractResourceConfigMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractResourceConfigMojo.java @@ -43,7 +43,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -71,7 +70,7 @@ import static org.graalvm.buildtools.model.resources.Helper.asNamedValues; import static org.graalvm.buildtools.model.resources.Helper.asPatternValues; -public abstract class AbstractResourceConfigMojo extends AbstractMojo { +public abstract class AbstractResourceConfigMojo extends AbstractSkippableMojo { @Parameter(defaultValue = "${project}", readonly = true) protected MavenProject mavenProject; @@ -108,7 +107,7 @@ public abstract class AbstractResourceConfigMojo extends AbstractMojo { private boolean ignoreExistingResourcesConfig; @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { Set includes = asPatternValues(resourceIncludedPatterns); Set excludes = asPatternValues(resourceExcludedPatterns); Set bundles = asNamedValues(resourceBundles); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractSkippableMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractSkippableMojo.java new file mode 100644 index 0000000000..daa588f4cf --- /dev/null +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractSkippableMojo.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.graalvm.buildtools.maven; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Parameter; + +public abstract class AbstractSkippableMojo extends AbstractMojo { + + // A root plugin configuration skips every goal before its goal-specific work begins. §FS-config-model.6. + @Parameter(property = "skip", defaultValue = "false") + private boolean skip; + + @Override + public final void execute() throws MojoExecutionException, MojoFailureException { + if (skip) { + getLog().info("Skipping native Maven plugin goal (parameter 'skip' is true)."); + return; + } + executeInternal(); + } + + protected abstract void executeInternal() throws MojoExecutionException, MojoFailureException; +} diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AddReachabilityMetadataMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AddReachabilityMetadataMojo.java index 1a3456dc87..2befa984ae 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AddReachabilityMetadataMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AddReachabilityMetadataMojo.java @@ -78,7 +78,7 @@ public class AddReachabilityMetadataMojo extends AbstractNativeMojo { @Override - public void execute() throws MojoExecutionException, MojoFailureException { + protected void executeInternal() throws MojoExecutionException, MojoFailureException { configureMetadataRepository(); project.getArtifacts().stream().filter(this::isInScope) .forEach(dependency -> maybeAddDependencyMetadata(dependency, null)); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/DeprecatedNativeBuildMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/DeprecatedNativeBuildMojo.java index 024cb1d567..d944f4cd43 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/DeprecatedNativeBuildMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/DeprecatedNativeBuildMojo.java @@ -57,9 +57,9 @@ public class DeprecatedNativeBuildMojo extends NativeCompileNoForkMojo { @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { logger.warn("'native:build' goal is deprecated. Use 'native:compile-no-fork' instead."); - super.execute(); + super.executeInternal(); } } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/ListLibrariesMissingMetadataMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/ListLibrariesMissingMetadataMojo.java index f69db386c9..49086ae66f 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/ListLibrariesMissingMetadataMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/ListLibrariesMissingMetadataMojo.java @@ -82,7 +82,7 @@ public class ListLibrariesMissingMetadataMojo extends AbstractNativeMojo { private File reportFile; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + protected void executeInternal() throws MojoExecutionException, MojoFailureException { if (!isMetadataRepositoryEnabled()) { throw new MojoExecutionException("GraalVM reachability metadata repository is disabled."); } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java index 595ee9cbfd..bc7c94e750 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MergeAgentFilesMojo.java @@ -44,7 +44,6 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.graalvm.buildtools.maven.config.AbstractMergeAgentFilesMojo; import org.graalvm.buildtools.maven.config.agent.AgentConfiguration; @@ -65,9 +64,6 @@ */ @Mojo(name = "merge-agent-files", defaultPhase = LifecyclePhase.TEST) public class MergeAgentFilesMojo extends AbstractMergeAgentFilesMojo { - @Parameter(defaultValue = "${project}", readonly = true, required = true) - protected MavenProject project; - @Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true) protected String target; @@ -82,7 +78,7 @@ public class MergeAgentFilesMojo extends AbstractMergeAgentFilesMojo { private static final List DEFAULT_DIRS = Arrays.asList("main", "test"); @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { // we need this mojo to be executed only once numberOfExecutions++; if (numberOfExecutions > 1) { diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MetadataCopyMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MetadataCopyMojo.java index 099ec8b79e..5f237dac85 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MetadataCopyMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/MetadataCopyMojo.java @@ -83,7 +83,7 @@ public class MetadataCopyMojo extends AbstractMergeAgentFilesMojo { private MavenSession session; @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { if (agentConfiguration != null && (agentConfiguration.isEnabled() || agentIsEnabledFromCmd())) { // in direct mode user is fully responsible for agent configuration, and we will not execute anything besides line that user provided if (agentConfiguration.getDefaultMode().equalsIgnoreCase("direct")) { diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeBuildDynamicAccessMetadataMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeBuildDynamicAccessMetadataMojo.java index 83c013cb72..ec19a8c935 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeBuildDynamicAccessMetadataMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeBuildDynamicAccessMetadataMojo.java @@ -97,7 +97,7 @@ public class NativeBuildDynamicAccessMetadataMojo extends AbstractNativeMojo { private File outputJson; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + protected void executeInternal() throws MojoExecutionException, MojoFailureException { configureMetadataRepository(); File jsonFile = ((FileSystemRepository) metadataRepository).getRootDirectory().resolve(LIBRARY_AND_FRAMEWORK_LIST).toFile(); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java index 24f86e5954..d6939eeb2c 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeCompileNoForkMojo.java @@ -98,7 +98,7 @@ protected List getDependencyScopes() { } @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { if (skip) { logger.info("Skipping native-image generation (parameter 'skipNativeBuild' is true)."); return; diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java index 2c12ea2ac9..95e1b18ae2 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/NativeTestMojo.java @@ -162,7 +162,7 @@ protected void addInferredDependenciesToClasspath() { } @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { if (skipTests || skipNativeTests) { logger.info("Skipping native-image tests (parameter 'skipTests' or 'skipNativeTests' is true)."); return; diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java index cf61612aaf..3ea0a5220c 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/WriteArgsFileMojo.java @@ -69,7 +69,7 @@ public class WriteArgsFileMojo extends NativeCompileNoForkMojo { public static final String PROPERTY_NAME = "graalvm.native-image.args-file"; @Override - public void execute() throws MojoExecutionException { + protected void executeInternal() throws MojoExecutionException { List args = getBuildArgs(); getLog().debug("Cleaning old native image build args"); diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/config/AbstractMergeAgentFilesMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/config/AbstractMergeAgentFilesMojo.java index 6b3ec22923..21b5ee95ba 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/config/AbstractMergeAgentFilesMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/config/AbstractMergeAgentFilesMojo.java @@ -42,12 +42,12 @@ package org.graalvm.buildtools.maven.config; import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.logging.Logger; +import org.graalvm.buildtools.maven.AbstractSkippableMojo; import org.graalvm.buildtools.utils.NativeImageConfigurationUtils; import java.io.File; @@ -55,8 +55,7 @@ import static org.graalvm.buildtools.utils.NativeImageUtils.nativeImageConfigureFileName; -public abstract class AbstractMergeAgentFilesMojo extends AbstractMojo { - +public abstract class AbstractMergeAgentFilesMojo extends AbstractSkippableMojo { @Component protected Logger logger; diff --git a/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy index a6c5cfc677..474a55f355 100644 --- a/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy +++ b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy @@ -78,7 +78,7 @@ class AbstractNativeImageMojoTest extends Specification { private static class TestNativeImageMojo extends AbstractNativeImageMojo { @Override - void execute() { + protected void executeInternal() { } @Override diff --git a/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeMojoTest.groovy b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeMojoTest.groovy index f093673277..1056ed489b 100644 --- a/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeMojoTest.groovy +++ b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeMojoTest.groovy @@ -82,7 +82,7 @@ class AbstractNativeMojoTest extends Specification { } @Override - void execute() { + protected void executeInternal() { } @Override