You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/21 12:27:57 UTC
(maven-invoker) branch master updated: Point the deprecation at the standalone maven-executor
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git
The following commit(s) were added to refs/heads/master by this push:
new cc6aed3 Point the deprecation at the standalone maven-executor
cc6aed3 is described below
commit cc6aed32df4b565898c55158b6b99c59d4e9937b
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Mon Sep 21 13:51:19 2026 +0200
Point the deprecation at the standalone maven-executor
maven-executor has its own repository and release now (org.apache.maven.executor:maven-executor,
Java 8, no dependencies); the migration guide is rewritten against its real API, the
previous one used classes that never shipped.
---
MIGRATION.md | 319 ++++++++-------------
README.md | 2 +-
pom.xml | 2 +-
.../shared/invoker/DefaultInvocationRequest.java | 2 +-
.../shared/invoker/DefaultInvocationResult.java | 2 +-
.../maven/shared/invoker/DefaultInvoker.java | 2 +-
.../maven/shared/invoker/InvocationRequest.java | 2 +-
.../maven/shared/invoker/InvocationResult.java | 2 +-
.../org/apache/maven/shared/invoker/Invoker.java | 2 +-
.../apache/maven/shared/invoker/package-info.java | 19 +-
src/site/markdown/index.md | 2 +-
src/site/markdown/migration.md | 268 +++++++++--------
src/site/markdown/usage.md | 2 +-
13 files changed, 270 insertions(+), 356 deletions(-)
diff --git a/MIGRATION.md b/MIGRATION.md
index d984103..d582938 100644
--- a/MIGRATION.md
+++ b/MIGRATION.md
@@ -14,281 +14,204 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
# Migration from maven-invoker to maven-executor
## Overview
-The `maven-invoker` component is deprecated and replaced by [`maven-executor`](https://github.com/apache/maven/tree/master/impl/maven-executor), which provides a modern, unified API for programmatically invoking Maven builds.
-
-## Why Migrate?
-
-**maven-executor** offers several advantages:
+The `maven-invoker` component is deprecated and replaced by [maven-executor](https://github.com/apache/maven-executor), a standalone library that runs Maven 3.9+ and Maven 4 programmatically, forked or embedded. Its only artifact, `org.apache.maven.executor:maven-executor`, has no dependencies and is built for Java 8, so it fits plugins on the 3.x line as well as Maven 4 code.
-- **Unified API**: Simple, consistent API that doesn't require updates when Maven CLI changes
-- **Maven 3.9+ and Maven 4+ Support**: Works seamlessly with both Maven versions
-- **Multiple Execution Modes**: Supports both forked and embedded execution
-- **Better Environment Isolation**: Proper isolation of environment variables and system properties
-- **Zero Dependencies**: Completely standalone, no additional dependencies required
-- **Maintained**: Actively used in Maven 4 Integration Tests
+## Dependency changes
-## Dependency Changes
-
-### Old (maven-invoker)
+Old:
```xml
<dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-invoker</artifactId>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-invoker</artifactId>
</dependency>
```
-### New (maven-executor)
-
-**Option 1: Using Maven 4+ (recommended)**
+New:
```xml
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-executor</artifactId>
- <version>4.0.0-rc5</version>
+ <groupId>org.apache.maven.executor</groupId>
+ <artifactId>maven-executor</artifactId>
+ <version>1.0.0</version>
</dependency>
```
-> **Note**: Check the latest Maven 4 releases for current version numbers.
+Check [Maven Central](https://central.sonatype.com/artifact/org.apache.maven.executor/maven-executor) for the current version.
+
+## What changes
-## API Comparison and Migration Examples
+maven-invoker models the Maven command line as setters on `InvocationRequest` (`setGoals`, `setDebug`, `setOffline`, ...) and turns them into arguments for the `mvn` script. maven-executor takes the arguments as you would type them, and adds what a script cannot express: the working directory, the environment, JVM system properties, the output streams, and a timeout. In practice a migration replaces each setter with the equivalent CLI option and moves the process settings to the request [...]
-### Basic Invocation
+| maven-invoker | maven-executor |
+|---|---|
+| `Invoker invoker = new DefaultInvoker(); invoker.setMavenHome(dir)` | `new ForkedMavenExecutor(dir.toPath())` or `new EmbeddedMavenExecutor(dir.toPath())`; `ExecutorRequest.discoverInstallationDirectory()` reads `maven.home` |
+| `request.setBaseDirectory(dir)` | `.cwd(dir.toPath())` |
+| `request.setPomFile(file)` | `.argument("-f").argument(file.getPath())`, or `.cwd(...)` on the project directory |
+| `request.setGoals(list)` | `.arguments(list)` |
+| `request.setProfiles(list)` | `.argument("-P" + String.join(",", list))` |
+| `request.setBatchMode(true)`, `setOffline(true)`, `setDebug(true)`, `setQuiet(true)`, `setShowErrors(true)`, `setShowVersion(true)`, `setUpdateSnapshots(true)` | `.argument("-B")`, `"-o"`, `"-X"`, `"-q"`, `"-e"`, `"-V"`, `"-U"` |
+| `request.setProperties(props)` | one `.argument("-Dkey=value")` per property |
+| `request.setUserSettingsFile(file)`, `setGlobalSettingsFile(file)`, `setToolchainsFile(file)` | `.argument("-s").argument(path)`, `"-gs"`, `"-t"` |
+| `request.setLocalRepositoryDirectory(dir)` | `.argument("-Dmaven.repo.local=" + dir)` |
+| `request.setThreads("4")` | `.argument("-T").argument("4")` |
+| `request.setReactorFailureBehavior(...)` | `.argument("--fail-at-end")`, `"--fail-fast"`, `"--fail-never"` |
+| `request.setJavaHome(dir)` | `.environmentVariable("JAVA_HOME", dir.getPath())` (forked) |
+| `request.setMavenOpts(opts)` | `.environmentVariable("MAVEN_OPTS", opts)` (forked), or `.jvmArgument(...)` |
+| `request.addShellEnvironment(k, v)` | `.environmentVariable(k, v)` |
+| `request.setOutputHandler(handler)`, `setErrorHandler(handler)` | `.stdOut(stream)`, `.stdErr(stream)`; or leave both unset and read `result.stdOutString()` |
+| `request.setInputStream(in)` | `.stdIn(in)` |
+| `request.setTimeoutInSeconds(n)` | `.executionTimeout(Duration.ofSeconds(n))` |
+| `request.setMavenExecutable(file)` | `.command("mvnDebug")` for the sibling scripts of the installation; another executable is not supported |
+| `result.getExitCode()`, `result.getExecutionException()` | `result.exitCode()` (an `Optional<Integer>`), `result.success()`; failures to start Maven throw `ExecutorException` |
-#### Old Code (maven-invoker)
+## Examples
+
+### Run goals in a project
+
+Old:
```java
import org.apache.maven.shared.invoker.*;
-import java.io.File;
-import java.util.Collections;
InvocationRequest request = new DefaultInvocationRequest();
-request.setPomFile(new File("/path/to/pom.xml"));
-request.setGoals(Collections.singletonList("install"));
+request.setBaseDirectory(new File("/path/to/project"));
+request.setGoals(Arrays.asList("clean", "install"));
+request.setBatchMode(true);
Invoker invoker = new DefaultInvoker();
+invoker.setMavenHome(new File("/path/to/maven"));
InvocationResult result = invoker.execute(request);
-
if (result.getExitCode() != 0) {
throw new IllegalStateException("Build failed.");
}
```
-#### New Code (maven-executor)
+New:
```java
-import org.apache.maven.api.cli.*;
-import org.apache.maven.cling.executor.*;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-// Using forked executor
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to"))
- .command("mvn")
- .args(new String[]{"install"})
- .build();
-
-ForkedExecutor executor = new ForkedExecutor();
-int exitCode = executor.execute(request);
-
-if (exitCode != 0) {
- throw new IllegalStateException("Build failed.");
+import org.apache.maven.executor.ExecutorRequest;
+import org.apache.maven.executor.ExecutorResult;
+import org.apache.maven.executor.forked.ForkedMavenExecutor;
+
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(Paths.get("/path/to/project"))
+ .arguments("-B", "clean", "install")
+ .build();
+
+try (ForkedMavenExecutor executor = new ForkedMavenExecutor(Paths.get("/path/to/maven"))) {
+ ExecutorResult result = executor.execute(request);
+ if (!result.success()) {
+ throw new IllegalStateException("Build failed: " + result.stdOutString().orElse(""));
+ }
}
```
-### Setting Goals and Options
+`ExecutorRequest.mavenBuilder()` starts from the current working directory and user home, and captures the output as a string unless you set streams.
+
+### Options and properties
-#### Old Code (maven-invoker)
+Old:
```java
-InvocationRequest request = new DefaultInvocationRequest();
-request.setPomFile(new File("/path/to/pom.xml"));
-request.setGoals(Arrays.asList("clean", "install"));
-request.setBatchMode(true);
request.setOffline(true);
request.setDebug(true);
-request.setProperties(properties);
+request.setProfiles(Arrays.asList("ci", "fast"));
+request.setUserSettingsFile(settings);
+request.setLocalRepositoryDirectory(repo);
+Properties props = new Properties();
+props.setProperty("skipTests", "true");
+request.setProperties(props);
```
-#### New Code (maven-executor)
+New:
```java
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to"))
- .command("mvn")
- .args(new String[]{
- "clean", "install",
- "--batch-mode",
- "--offline",
- "--debug",
- "-Dproperty1=value1",
- "-Dproperty2=value2"
- })
- .build();
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("-o", "-X", "-Pci,fast", "-s", settings.toString(), "-Dmaven.repo.local=" + repo, "-DskipTests=true", "verify")
+ .build();
```
-### Maven Home Configuration
-
-#### Old Code (maven-invoker)
-
-```java
-Invoker invoker = new DefaultInvoker();
-invoker.setMavenHome(new File("/path/to/maven"));
-```
+### Stream the output
-#### New Code (maven-executor)
+Old:
```java
-// Maven home is automatically detected from MAVEN_HOME or M2_HOME
-// or can be specified via command path
-ExecutorRequest request = ExecutorRequest.builder()
- .command("/path/to/maven/bin/mvn")
- .args(new String[]{"install"})
- .build();
+request.setOutputHandler(line -> log.info(line));
+request.setErrorHandler(line -> log.error(line));
```
-### Local Repository Configuration
-
-#### Old Code (maven-invoker)
+New:
```java
-InvocationRequest request = new DefaultInvocationRequest();
-request.setLocalRepositoryDirectory(new File("/path/to/local/repo"));
+try (OutputStream out = Files.newOutputStream(logFile)) {
+ ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("verify")
+ .stdOut(out)
+ .stdErr(out)
+ .build();
+ executor.execute(request);
+}
```
-#### New Code (maven-executor)
-
-```java
-ExecutorRequest request = ExecutorRequest.builder()
- .args(new String[]{
- "install",
- "-Dmaven.repo.local=/path/to/local/repo"
- })
- .build();
-```
+Maven's log and the transfer messages go to `stdOut`; `stdErr` carries what the JVM prints before Maven starts. A line-oriented handler becomes an `OutputStream` that splits on line ends.
-### Capturing Output
+### Embedded execution
-#### Old Code (maven-invoker)
+maven-invoker only forks. maven-executor can run Maven inside the current JVM, which is faster for many short builds:
```java
-InvocationOutputHandler outputHandler = new InvocationOutputHandler() {
- @Override
- public void consumeLine(String line) {
- System.out.println(line);
- }
-};
-
-InvocationRequest request = new DefaultInvocationRequest();
-request.setOutputHandler(outputHandler);
-```
-
-#### New Code (maven-executor)
+import org.apache.maven.executor.embedded.EmbeddedMavenExecutor;
-```java
-// Output handling through standard Java ProcessBuilder mechanisms
-ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.PIPE;
-
-// Or use custom output streams
-ExecutorRequest request = ExecutorRequest.builder()
- .args(new String[]{"install"})
- .outputRedirect(yourOutputStream)
- .build();
+try (EmbeddedMavenExecutor executor = new EmbeddedMavenExecutor(installation)) {
+ executor.execute(request);
+}
```
-### Embedded Execution
-
-#### Old Code (maven-invoker)
+`ExecutorHelper.forMavenInstallation(installation, ExecutorHelper.Mode.AUTO)` picks the embedded executor unless the request needs a fork (environment variables or JVM arguments). Embedded runs share the JVM, so a build that sets system properties or leaks threads affects the caller.
-```java
-// maven-invoker only supports forked execution
-```
+### Environment and JVM
-#### New Code (maven-executor)
+Old:
```java
-// maven-executor supports embedded execution!
-import org.apache.maven.cling.executor.EmbeddedExecutor;
-
-EmbeddedExecutor executor = new EmbeddedExecutor();
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to/project"))
- .args(new String[]{"install"})
- .build();
-
-int exitCode = executor.execute(request);
+request.setJavaHome(new File("/opt/jdk17"));
+request.setMavenOpts("-Xmx1g");
+request.addShellEnvironment("CI", "true");
```
-### Environment Variables
-
-#### Old Code (maven-invoker)
+New:
```java
-InvocationRequest request = new DefaultInvocationRequest();
-request.setShellEnvironmentInherited(true);
-// or
-request.addShellEnvironment("MY_VAR", "value");
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("verify")
+ .environmentVariable("JAVA_HOME", "/opt/jdk17")
+ .environmentVariable("MAVEN_OPTS", "-Xmx1g")
+ .environmentVariable("CI", "true")
+ .skipMavenRc(true)
+ .build();
```
-#### New Code (maven-executor)
+The forked executor starts from a clean environment, so pass what the build needs; `skipMavenRc(true)` keeps the user's `.mavenrc` out of the run.
-```java
-Map<String, String> env = new HashMap<>();
-env.put("MY_VAR", "value");
+## Migration checklist
-ExecutorRequest request = ExecutorRequest.builder()
- .args(new String[]{"install"})
- .environment(env)
- .build();
-```
+- Replace the dependency and the `org.apache.maven.shared.invoker` imports.
+- Replace each `InvocationRequest` setter with the CLI option from the table.
+- Move Maven home from `Invoker.setMavenHome` to the executor constructor; in tests run under Surefire or Failsafe, pass `maven.home` explicitly through `systemPropertyVariables`, the forked JVM does not inherit it.
+- Replace the output handlers with streams, or read `stdOutString()`.
+- Check the exit code through `ExecutorResult.success()` and catch `ExecutorException` for a Maven that could not start.
-## Complete Migration Checklist
-
-- [ ] Update dependencies in `pom.xml`
-- [ ] Replace `InvocationRequest` with `ExecutorRequest`
-- [ ] Replace `Invoker` with `ForkedExecutor` or `EmbeddedExecutor`
-- [ ] Convert file paths from `File` to `Path`/`Paths`
-- [ ] Convert goals and options to command-line arguments array
-- [ ] Update output handling mechanism
-- [ ] Update environment variable handling
-- [ ] Update system property handling
-- [ ] Update test configurations
-- [ ] Verify Maven home detection or configuration
-- [ ] Test with both Maven 3.9+ and Maven 4+ if needed
-
-## Key Differences Summary
-
-| Feature | maven-invoker | maven-executor |
-|---------|--------------|----------------|
-| API Style | Request/Invoker objects | Builder pattern with args array |
-| Maven Versions | Maven 2.x, 3.x | Maven 3.9+, 4+ |
-| Execution Modes | Forked only | Forked and Embedded |
-| Dependencies | Has dependencies | Zero dependencies |
-| CLI Mapping | Manual mapping in code | Direct CLI args |
-| Maintenance | Requires updates for CLI changes | No updates needed for CLI changes |
-
-## Additional Resources
-
-- [maven-executor source code](https://github.com/apache/maven/tree/master/impl/maven-executor)
-- [maven-executor CLI API](https://github.com/apache/maven/tree/master/impl/maven-executor/src/main/java/org/apache/maven/api/cli)
-- [maven-executor implementation](https://github.com/apache/maven/tree/master/impl/maven-executor/src/main/java/org/apache/maven/cling/executor)
-- [Maven 4 Integration Tests using maven-executor](https://github.com/apache/maven/blob/master/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java)
-- [Issue #164 - Deprecation announcement](https://github.com/apache/maven-invoker/issues/164)
-- [Related discussion in maven-verifier](https://github.com/apache/maven-verifier/issues/186)
-
-## Need Help?
-
-If you encounter migration issues or have questions:
-
-1. Check the [maven-executor source code](https://github.com/apache/maven/tree/master/impl/maven-executor) for examples
-2. Review [Maven 4 IT tests](https://github.com/apache/maven/tree/master/its) that use maven-executor
-3. Open an issue on the [maven-invoker repository](https://github.com/apache/maven-invoker/issues) for migration-specific questions
-4. Contact the [Maven developer mailing list](https://maven.apache.org/mailing-lists.html)
+## Resources
+- [maven-executor repository](https://github.com/apache/maven-executor)
+- [Maven 4 integration tests](https://github.com/apache/maven/tree/master/its), the first consumer of the API
+- [Issue #164, the deprecation](https://github.com/apache/maven-invoker/issues/164)
+- [maven-verifier's migration guide](https://github.com/apache/maven-verifier/blob/master/MIGRATION.md), for the verifier side of the same move
diff --git a/README.md b/README.md
index 3bf6402..ca5f311 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Contributing to [Apache Maven Invoker](https://maven.apache.org/shared/maven-inv
> **⚠️ DEPRECATION NOTICE**
>
-> This project is **deprecated** and will be replaced by [**maven-executor**](https://github.com/apache/maven/tree/master/impl/maven-executor).
+> This project is **deprecated** and replaced by [**maven-executor**](https://github.com/apache/maven-executor) (`org.apache.maven.executor:maven-executor`, Java 8, no dependencies).
>
> **Users should migrate to maven-executor**, which offers:
> - Unified and simpler API that doesn't require updates when Maven CLI changes
diff --git a/pom.xml b/pom.xml
index 883c389..1acaa6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@ under the License.
<version>3.3.1-SNAPSHOT</version>
<name>Apache Maven Invoker</name>
- <description>DEPRECATED: This component is deprecated and replaced by maven-executor (https://github.com/apache/maven/tree/master/impl/maven-executor). Please migrate to maven-executor for Maven 3.9+ and Maven 4+ support with improved API and features.</description>
+ <description>DEPRECATED: This component is deprecated and replaced by maven-executor (https://github.com/apache/maven-executor). Please migrate to maven-executor for Maven 3.9+ and Maven 4+ support with improved API and features.</description>
<contributors>
<contributor>
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
index 9b4657f..05d1af8 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
@@ -32,7 +32,7 @@ import java.util.Properties;
* Specifies the parameters used to control a Maven invocation.
*
* @deprecated This class is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* ExecutorRequest.builder() instead.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationResult.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationResult.java
index eff08a7..eacf564 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationResult.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationResult.java
@@ -24,7 +24,7 @@ import org.apache.maven.shared.utils.cli.CommandLineException;
* Describes the result of a Maven invocation.
*
* @deprecated This class is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* instead.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
index 9d9375f..f2ba03e 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
@@ -32,7 +32,7 @@ import org.apache.maven.shared.utils.cli.Commandline;
* Class intended to be used by clients who wish to invoke a forked Maven process from their applications
*
* @deprecated This class is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* ForkedExecutor or EmbeddedExecutor instead.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
index e1a9e05..4f9270a 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
@@ -29,7 +29,7 @@ import java.util.Properties;
* Specifies the parameters used to control a Maven invocation.
*
* @deprecated This interface is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* ExecutorRequest instead, which uses a builder pattern and direct CLI arguments.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationResult.java b/src/main/java/org/apache/maven/shared/invoker/InvocationResult.java
index 8db839c..45fb0d4 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationResult.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationResult.java
@@ -24,7 +24,7 @@ import org.apache.maven.shared.utils.cli.CommandLineException;
* Describes the result of a Maven invocation.
*
* @deprecated This interface is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* which returns exit codes directly.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/Invoker.java b/src/main/java/org/apache/maven/shared/invoker/Invoker.java
index bb2263e..5ea64b8 100644
--- a/src/main/java/org/apache/maven/shared/invoker/Invoker.java
+++ b/src/main/java/org/apache/maven/shared/invoker/Invoker.java
@@ -25,7 +25,7 @@ import java.io.InputStream;
* Provides a facade to invoke Maven.
*
* @deprecated This component is deprecated. Use
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>
* instead, which provides better Maven 3.9+ and Maven 4+ support with a unified API.
* See the <a href="https://maven.apache.org/shared/maven-invoker/migration.html">Migration Guide</a>
* for details.
diff --git a/src/main/java/org/apache/maven/shared/invoker/package-info.java b/src/main/java/org/apache/maven/shared/invoker/package-info.java
index fc364ae..51b9679 100644
--- a/src/main/java/org/apache/maven/shared/invoker/package-info.java
+++ b/src/main/java/org/apache/maven/shared/invoker/package-info.java
@@ -19,7 +19,7 @@
/**
* <p><strong>DEPRECATED:</strong> This package is deprecated and will be replaced by
- * <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>.</p>
+ * <a href="https://github.com/apache/maven-executor">maven-executor</a>.</p>
*
* <p>The {@code maven-invoker} component provides an API for programmatically invoking Maven builds.
* However, it is being replaced by {@code maven-executor} which offers significant improvements:</p>
@@ -51,24 +51,27 @@
*
* <p>New code (maven-executor):</p>
* <pre>{@code
- * ExecutorRequest request = ExecutorRequest.builder()
+ * ExecutorRequest request = ExecutorRequest.mavenBuilder()
* .cwd(Paths.get("/path/to"))
- * .command("mvn")
- * .args(new String[]{"install"})
+ * .arguments("install")
* .build();
*
- * ForkedExecutor executor = new ForkedExecutor();
- * int exitCode = executor.execute(request);
+ * try (ForkedMavenExecutor executor = new ForkedMavenExecutor(Paths.get("/path/to/maven"))) {
+ * ExecutorResult result = executor.execute(request);
+ * if (!result.success()) {
+ * throw new IllegalStateException("Build failed.");
+ * }
+ * }
* }</pre>
*
* <h2>Support</h2>
* <ul>
* <li><a href="https://github.com/apache/maven-invoker/issues/164">Issue #164 - Deprecation Announcement</a></li>
- * <li><a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor Source Code</a></li>
+ * <li><a href="https://github.com/apache/maven-executor">maven-executor Source Code</a></li>
* <li><a href="https://maven.apache.org/mailing-lists.html">Maven Mailing Lists</a></li>
* </ul>
*
- * @deprecated Use <a href="https://github.com/apache/maven/tree/master/impl/maven-executor">maven-executor</a>
+ * @deprecated Use <a href="https://github.com/apache/maven-executor">maven-executor</a>
* instead. This package will be removed in a future version.
*/
package org.apache.maven.shared.invoker;
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index bd2b066..581e057 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -20,7 +20,7 @@ under the License.
## *DEPRECATION NOTICE*
-- This project is deprecated and will be replaced by [maven-executor](https://github.com/apache/maven/tree/master/impl/maven-executor).
+- This project is deprecated and replaced by [maven-executor](https://github.com/apache/maven-executor).
Users should migrate to maven-executor, which offers:
- Unified and simpler API that doesn't require updates when Maven CLI changes
diff --git a/src/site/markdown/migration.md b/src/site/markdown/migration.md
index 4d4d9a9..6e60c17 100644
--- a/src/site/markdown/migration.md
+++ b/src/site/markdown/migration.md
@@ -20,212 +20,200 @@ under the License.
## Overview
-The `maven-invoker` component is deprecated and replaced by [maven-executor](https://github.com/apache/maven/tree/master/impl/maven-executor), which provides a modern, unified API for programmatically invoking Maven builds.
+The `maven-invoker` component is deprecated and replaced by [maven-executor](https://github.com/apache/maven-executor), a standalone library that runs Maven 3.9+ and Maven 4 programmatically, forked or embedded. Its only artifact, `org.apache.maven.executor:maven-executor`, has no dependencies and is built for Java 8, so it fits plugins on the 3.x line as well as Maven 4 code.
-## Why Migrate?
+## Dependency changes
-`maven-executor` offers several advantages:
-
-- Unified API: Simple, consistent API that doesn't require updates when Maven CLI changes
-- Maven 3.9+ and Maven 4+ Support: Works seamlessly with both Maven versions
-- Multiple Execution Modes: Supports both forked and embedded execution
-- Better Environment Isolation: Proper isolation of environment variables and system properties
-- Zero Dependencies: Completely standalone, no additional dependencies required
-- Maintained: Actively used in Maven 4 Integration Tests
-## Dependency Changes
-
-### Old (maven-invoker)
+Old:
```xml
<dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-invoker</artifactId>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-invoker</artifactId>
</dependency>
```
-### New (maven-executor)
+New:
```xml
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-executor</artifactId>
- <version>4.0.0-rc5</version>
+ <groupId>org.apache.maven.executor</groupId>
+ <artifactId>maven-executor</artifactId>
+ <version>1.0.0</version>
</dependency>
```
-**Note:** Since maven-executor is part of Maven 4, check the latest Maven 4 releases for current version numbers.
+Check [Maven Central](https://central.sonatype.com/artifact/org.apache.maven.executor/maven-executor) for the current version.
+
+## What changes
+
+maven-invoker models the Maven command line as setters on `InvocationRequest` (`setGoals`, `setDebug`, `setOffline`, ...) and turns them into arguments for the `mvn` script. maven-executor takes the arguments as you would type them, and adds what a script cannot express: the working directory, the environment, JVM system properties, the output streams, and a timeout. In practice a migration replaces each setter with the equivalent CLI option and moves the process settings to the request [...]
+
+| maven-invoker | maven-executor |
+|---|---|
+| `Invoker invoker = new DefaultInvoker(); invoker.setMavenHome(dir)` | `new ForkedMavenExecutor(dir.toPath())` or `new EmbeddedMavenExecutor(dir.toPath())`; `ExecutorRequest.discoverInstallationDirectory()` reads `maven.home` |
+| `request.setBaseDirectory(dir)` | `.cwd(dir.toPath())` |
+| `request.setPomFile(file)` | `.argument("-f").argument(file.getPath())`, or `.cwd(...)` on the project directory |
+| `request.setGoals(list)` | `.arguments(list)` |
+| `request.setProfiles(list)` | `.argument("-P" + String.join(",", list))` |
+| `request.setBatchMode(true)`, `setOffline(true)`, `setDebug(true)`, `setQuiet(true)`, `setShowErrors(true)`, `setShowVersion(true)`, `setUpdateSnapshots(true)` | `.argument("-B")`, `"-o"`, `"-X"`, `"-q"`, `"-e"`, `"-V"`, `"-U"` |
+| `request.setProperties(props)` | one `.argument("-Dkey=value")` per property |
+| `request.setUserSettingsFile(file)`, `setGlobalSettingsFile(file)`, `setToolchainsFile(file)` | `.argument("-s").argument(path)`, `"-gs"`, `"-t"` |
+| `request.setLocalRepositoryDirectory(dir)` | `.argument("-Dmaven.repo.local=" + dir)` |
+| `request.setThreads("4")` | `.argument("-T").argument("4")` |
+| `request.setReactorFailureBehavior(...)` | `.argument("--fail-at-end")`, `"--fail-fast"`, `"--fail-never"` |
+| `request.setJavaHome(dir)` | `.environmentVariable("JAVA_HOME", dir.getPath())` (forked) |
+| `request.setMavenOpts(opts)` | `.environmentVariable("MAVEN_OPTS", opts)` (forked), or `.jvmArgument(...)` |
+| `request.addShellEnvironment(k, v)` | `.environmentVariable(k, v)` |
+| `request.setOutputHandler(handler)`, `setErrorHandler(handler)` | `.stdOut(stream)`, `.stdErr(stream)`; or leave both unset and read `result.stdOutString()` |
+| `request.setInputStream(in)` | `.stdIn(in)` |
+| `request.setTimeoutInSeconds(n)` | `.executionTimeout(Duration.ofSeconds(n))` |
+| `request.setMavenExecutable(file)` | `.command("mvnDebug")` for the sibling scripts of the installation; another executable is not supported |
+| `result.getExitCode()`, `result.getExecutionException()` | `result.exitCode()` (an `Optional<Integer>`), `result.success()`; failures to start Maven throw `ExecutorException` |
-## API Comparison
+## Examples
-### Basic Invocation
+### Run goals in a project
-Old Code (maven-invoker):
+Old:
```java
+import org.apache.maven.shared.invoker.*;
+
InvocationRequest request = new DefaultInvocationRequest();
-request.setPomFile(new File("/path/to/pom.xml"));
-request.setGoals(Collections.singletonList("install"));
+request.setBaseDirectory(new File("/path/to/project"));
+request.setGoals(Arrays.asList("clean", "install"));
+request.setBatchMode(true);
Invoker invoker = new DefaultInvoker();
+invoker.setMavenHome(new File("/path/to/maven"));
InvocationResult result = invoker.execute(request);
-
if (result.getExitCode() != 0) {
throw new IllegalStateException("Build failed.");
}
```
-New Code (maven-executor):
+New:
```java
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to"))
- .command("mvn")
- .args(new String[]{"install"})
- .build();
-
-ForkedExecutor executor = new ForkedExecutor();
-int exitCode = executor.execute(request);
-
-if (exitCode != 0) {
- throw new IllegalStateException("Build failed.");
+import org.apache.maven.executor.ExecutorRequest;
+import org.apache.maven.executor.ExecutorResult;
+import org.apache.maven.executor.forked.ForkedMavenExecutor;
+
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(Paths.get("/path/to/project"))
+ .arguments("-B", "clean", "install")
+ .build();
+
+try (ForkedMavenExecutor executor = new ForkedMavenExecutor(Paths.get("/path/to/maven"))) {
+ ExecutorResult result = executor.execute(request);
+ if (!result.success()) {
+ throw new IllegalStateException("Build failed: " + result.stdOutString().orElse(""));
+ }
}
```
-### Setting Goals and Options
+`ExecutorRequest.mavenBuilder()` starts from the current working directory and user home, and captures the output as a string unless you set streams.
+
+### Options and properties
-Old Code (maven-invoker):
+Old:
```java
-InvocationRequest request = new DefaultInvocationRequest();
-request.setPomFile(new File("/path/to/pom.xml"));
-request.setGoals(Arrays.asList("clean", "install"));
-request.setBatchMode(true);
request.setOffline(true);
request.setDebug(true);
+request.setProfiles(Arrays.asList("ci", "fast"));
+request.setUserSettingsFile(settings);
+request.setLocalRepositoryDirectory(repo);
+Properties props = new Properties();
+props.setProperty("skipTests", "true");
+request.setProperties(props);
```
-New Code (maven-executor):
+New:
```java
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to"))
- .command("mvn")
- .args(new String[]{
- "clean", "install",
- "--batch-mode",
- "--offline",
- "--debug"
- })
- .build();
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("-o", "-X", "-Pci,fast", "-s", settings.toString(), "-Dmaven.repo.local=" + repo, "-DskipTests=true", "verify")
+ .build();
```
-### Embedded Execution
+### Stream the output
-maven-invoker only supports forked execution, while maven-executor supports both.
+Old:
```java
-import org.apache.maven.cling.executor.EmbeddedExecutor;
-
-EmbeddedExecutor executor = new EmbeddedExecutor();
-ExecutorRequest request = ExecutorRequest.builder()
- .cwd(Paths.get("/path/to/project"))
- .args(new String[]{"install"})
- .build();
-
-int exitCode = executor.execute(request);
+request.setOutputHandler(line -> log.info(line));
+request.setErrorHandler(line -> log.error(line));
```
-## Complete Migration Example
-
-Before (maven-invoker):
+New:
```java
-import org.apache.maven.shared.invoker.*;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Properties;
-
-public class MavenBuildRunner {
- private final Invoker invoker;
+try (OutputStream out = Files.newOutputStream(logFile)) {
+ ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("verify")
+ .stdOut(out)
+ .stdErr(out)
+ .build();
+ executor.execute(request);
+}
+```
- public MavenBuildRunner(File localRepo) {
- Invoker newInvoker = new DefaultInvoker();
- newInvoker.setLocalRepositoryDirectory(localRepo);
- this.invoker = newInvoker;
- }
+Maven's log and the transfer messages go to `stdOut`; `stdErr` carries what the JVM prints before Maven starts. A line-oriented handler becomes an `OutputStream` that splits on line ends.
- public void runBuild(File projectDir) throws Exception {
- InvocationRequest request = new DefaultInvocationRequest();
- request.setBaseDirectory(projectDir);
- request.setGoals(Arrays.asList("clean", "install"));
- request.setBatchMode(true);
+### Embedded execution
- Properties props = new Properties();
- props.setProperty("skipTests", "false");
- request.setProperties(props);
+maven-invoker only forks. maven-executor can run Maven inside the current JVM, which is faster for many short builds:
- InvocationResult result = invoker.execute(request);
+```java
+import org.apache.maven.executor.embedded.EmbeddedMavenExecutor;
- if (result.getExitCode() != 0) {
- throw new Exception("Build failed");
- }
- }
+try (EmbeddedMavenExecutor executor = new EmbeddedMavenExecutor(installation)) {
+ executor.execute(request);
}
```
-After (maven-executor):
+`ExecutorHelper.forMavenInstallation(installation, ExecutorHelper.Mode.AUTO)` picks the embedded executor unless the request needs a fork (environment variables or JVM arguments). Embedded runs share the JVM, so a build that sets system properties or leaks threads affects the caller.
-```java
-import org.apache.maven.api.cli.*;
-import org.apache.maven.cling.executor.*;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-
-public class MavenBuildRunner {
- private final ForkedExecutor executor;
- private final Path localRepo;
-
- public MavenBuildRunner(Path localRepo) {
- this.executor = new ForkedExecutor();
- this.localRepo = localRepo;
- }
+### Environment and JVM
- public void runBuild(Path projectDir) throws Exception {
- List<String> args = new ArrayList<>();
- args.add("clean");
- args.add("install");
- args.add("--batch-mode");
- args.add("-Dmaven.repo.local=" + localRepo.toString());
- args.add("-DskipTests=false");
+Old:
- ExecutorRequest request = ExecutorRequest.builder()
- .cwd(projectDir)
- .command("mvn")
- .args(args.toArray(new String[0]))
- .build();
+```java
+request.setJavaHome(new File("/opt/jdk17"));
+request.setMavenOpts("-Xmx1g");
+request.addShellEnvironment("CI", "true");
+```
- int exitCode = executor.execute(request);
+New:
- if (exitCode != 0) {
- throw new Exception("Build failed");
- }
- }
-}
+```java
+ExecutorRequest request = ExecutorRequest.mavenBuilder()
+ .cwd(projectDir)
+ .arguments("verify")
+ .environmentVariable("JAVA_HOME", "/opt/jdk17")
+ .environmentVariable("MAVEN_OPTS", "-Xmx1g")
+ .environmentVariable("CI", "true")
+ .skipMavenRc(true)
+ .build();
```
-## Additional Resources
+The forked executor starts from a clean environment, so pass what the build needs; `skipMavenRc(true)` keeps the user's `.mavenrc` out of the run.
+
+## Migration checklist
-- [maven-executor source code](https://github.com/apache/maven/tree/master/impl/maven-executor)
-- [Issue #164 - Deprecation announcement](https://github.com/apache/maven-invoker/issues/164)
-- [Related discussion in maven-verifier](https://github.com/apache/maven-verifier/issues/186)
-- [Maven developer mailing list](https://maven.apache.org/mailing-lists.html)
-- [Detailed Migration Guide (MIGRATION.md)](./MIGRATION.md)
-## Need Help?
+- Replace the dependency and the `org.apache.maven.shared.invoker` imports.
+- Replace each `InvocationRequest` setter with the CLI option from the table.
+- Move Maven home from `Invoker.setMavenHome` to the executor constructor; in tests run under Surefire or Failsafe, pass `maven.home` explicitly through `systemPropertyVariables`, the forked JVM does not inherit it.
+- Replace the output handlers with streams, or read `stdOutString()`.
+- Check the exit code through `ExecutorResult.success()` and catch `ExecutorException` for a Maven that could not start.
-If you encounter migration issues or have questions:
+## Resources
-1. Check the [maven-executor source code](https://github.com/apache/maven/tree/master/impl/maven-executor) for examples
-1. Review [Maven 4 IT tests](https://github.com/apache/maven/tree/master/its) that use maven-executor
-1. Open an issue on the [maven-invoker repository](https://github.com/apache/maven-invoker/issues)
-1. Contact the [Maven developer mailing list](https://maven.apache.org/mailing-lists.html)
+- [maven-executor repository](https://github.com/apache/maven-executor)
+- [Maven 4 integration tests](https://github.com/apache/maven/tree/master/its), the first consumer of the API
+- [Issue #164, the deprecation](https://github.com/apache/maven-invoker/issues/164)
+- [maven-verifier's migration guide](https://github.com/apache/maven-verifier/blob/master/MIGRATION.md), for the verifier side of the same move
diff --git a/src/site/markdown/usage.md b/src/site/markdown/usage.md
index 96ad1c6..60f3cdd 100644
--- a/src/site/markdown/usage.md
+++ b/src/site/markdown/usage.md
@@ -20,7 +20,7 @@ under the License.
## DEPRECATION NOTICE
-- This project is deprecated. Please migrate to [maven-executor](https://github.com/apache/maven/tree/master/impl/maven-executor).
+- This project is deprecated. Please migrate to [maven-executor](https://github.com/apache/maven-executor).
See [Migration Guide](./migration.html) for details.