You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/07/29 14:17:55 UTC

(maven-compiler-plugin) branch experiment/maven4-build-context created (now 769e031)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a change to branch experiment/maven4-build-context
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


      at 769e031  experiment: leverage BuildContext API for skip-execution signaling

This branch includes the following new commits:

     new 769e031  experiment: leverage BuildContext API for skip-execution signaling

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-compiler-plugin) 01/01: experiment: leverage BuildContext API for skip-execution signaling

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch experiment/maven4-build-context
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git

commit 769e031c3b1328b89b01c1208fb4b933256d3623
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Jul 29 16:17:40 2026 +0200

    experiment: leverage BuildContext API for skip-execution signaling
    
    Integrate the Maven 4 BuildContext API into the compiler plugin to
    signal markSkipExecution() when compilation is skipped. This covers:
    - CompilerMojo: when skipMain is true
    - TestCompilerMojo: when skip is true
    - AbstractCompilerMojo: when applyIncrementalBuild() returns false
    
    This enables downstream mojos to detect that the compiler was skipped
    and react accordingly (e.g., skip JAR creation).
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 pom.xml                                            |  2 +-
 .../plugin/compiler/AbstractCompilerMojo.java      | 10 ++++++
 .../apache/maven/plugin/compiler/CompilerMojo.java |  1 +
 .../maven/plugin/compiler/TestCompilerMojo.java    |  1 +
 .../plugin/compiler/CompilerMojoTestCase.java      | 37 +++++++++++++++++-----
 5 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4b016c7..1733d82 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,7 +82,7 @@ under the License.
 
   <properties>
     <javaVersion>17</javaVersion>
-    <mavenVersion>4.0.0-rc-4</mavenVersion>
+    <mavenVersion>4.1.0-SNAPSHOT</mavenVersion>
 
     <asmVersion>9.10.1</asmVersion>
     <guiceVersion>7.0.0</guiceVersion>
diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index cac92f9..f7f363e 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -64,6 +64,7 @@ import org.apache.maven.api.Toolchain;
 import org.apache.maven.api.Type;
 import org.apache.maven.api.annotations.Nonnull;
 import org.apache.maven.api.annotations.Nullable;
+import org.apache.maven.api.build.context.BuildContext;
 import org.apache.maven.api.di.Inject;
 import org.apache.maven.api.plugin.Log;
 import org.apache.maven.api.plugin.Mojo;
@@ -942,6 +943,14 @@ public abstract class AbstractCompilerMojo implements Mojo {
     @Inject
     protected MessageBuilderFactory messageBuilderFactory;
 
+    /**
+     * The build context for incremental build support.
+     * Used to signal to downstream plugins when compilation is skipped
+     * because all classes are up to date or there are no sources to compile.
+     */
+    @Inject
+    protected BuildContext buildContext;
+
     /**
      * The logger for reporting information or warnings to the user.
      * Currently, this is also used for console output.
@@ -1382,6 +1391,7 @@ public abstract class AbstractCompilerMojo implements Mojo {
     private void compile(final JavaCompiler compiler, final Options configuration) throws IOException {
         final ToolExecutor executor = createExecutor(null);
         if (!executor.applyIncrementalBuild(this, configuration)) {
+            buildContext.markSkipExecution();
             return;
         }
         Throwable failureCause = null;
diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
index 306ac59..5a968cb 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
@@ -192,6 +192,7 @@ public class CompilerMojo extends AbstractCompilerMojo {
     public void execute() throws MojoException {
         if (skipMain) {
             logger.info("Not compiling main sources");
+            buildContext.markSkipExecution();
             return;
         }
         try {
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 1cdc336..f10e282 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -246,6 +246,7 @@ public class TestCompilerMojo extends AbstractCompilerMojo {
     public void execute() throws MojoException {
         if (skip) {
             logger.info("Not compiling test sources");
+            buildContext.markSkipExecution();
             return;
         }
         super.execute();
diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
index e58e3ca..96287b4 100644
--- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
+++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
@@ -34,26 +34,32 @@ import java.util.Map;
 import org.apache.maven.api.PathScope;
 import org.apache.maven.api.Project;
 import org.apache.maven.api.Session;
+import org.apache.maven.api.build.context.BuildContext;
 import org.apache.maven.api.di.Inject;
+import org.apache.maven.api.di.Priority;
 import org.apache.maven.api.di.Provides;
 import org.apache.maven.api.di.Singleton;
 import org.apache.maven.api.model.Build;
 import org.apache.maven.api.model.Model;
 import org.apache.maven.api.plugin.Log;
-import org.apache.maven.api.plugin.testing.Basedir;
-import org.apache.maven.api.plugin.testing.InjectMojo;
-import org.apache.maven.api.plugin.testing.MojoExtension;
-import org.apache.maven.api.plugin.testing.MojoParameter;
-import org.apache.maven.api.plugin.testing.MojoTest;
-import org.apache.maven.api.plugin.testing.stubs.ProducedArtifactStub;
-import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
-import org.apache.maven.api.plugin.testing.stubs.SessionMock;
 import org.apache.maven.api.services.ArtifactManager;
 import org.apache.maven.api.services.MessageBuilderFactory;
+import org.apache.maven.api.services.PathMatcherFactory;
 import org.apache.maven.api.services.ToolchainManager;
 import org.apache.maven.impl.DefaultMessageBuilderFactory;
+import org.apache.maven.impl.DefaultPathMatcherFactory;
 import org.apache.maven.impl.InternalSession;
+import org.apache.maven.internal.build.context.impl.DefaultBuildContext;
+import org.apache.maven.internal.build.context.impl.FilesystemWorkspace;
 import org.apache.maven.plugin.compiler.stubs.CompilerStub;
+import org.apache.maven.testing.plugin.Basedir;
+import org.apache.maven.testing.plugin.InjectMojo;
+import org.apache.maven.testing.plugin.MojoExtension;
+import org.apache.maven.testing.plugin.MojoParameter;
+import org.apache.maven.testing.plugin.MojoTest;
+import org.apache.maven.testing.plugin.stubs.ProducedArtifactStub;
+import org.apache.maven.testing.plugin.stubs.ProjectStub;
+import org.apache.maven.testing.plugin.stubs.SessionMock;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@@ -495,4 +501,19 @@ public class CompilerMojoTestCase {
         stub.setBasedir(Path.of(MojoExtension.getBasedir()));
         return stub;
     }
+
+    @Provides
+    @Priority(10)
+    @SuppressWarnings("unused")
+    private static PathMatcherFactory pathMatcherFactory() {
+        return new DefaultPathMatcherFactory();
+    }
+
+    @Provides
+    @Priority(10)
+    @SuppressWarnings("unused")
+    private static BuildContext buildContext() {
+        return new DefaultBuildContext(
+                new FilesystemWorkspace(), null, new HashMap<>(), null, new DefaultPathMatcherFactory());
+    }
 }