Add seperate install and run goal

This commit is contained in:
2026-05-24 22:23:47 +02:00
parent bb75bba0a1
commit 303e3d910b
4 changed files with 186 additions and 1 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<groupId>org.strassburger</groupId>
<artifactId>mcrun-maven-plugin</artifactId>
<version>0.0.13</version>
<version>0.0.14</version>
<packaging>maven-plugin</packaging>
<name>MCRun Maven Plugin</name>
@@ -0,0 +1,74 @@
package org.strassburger.mcrun;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.strassburger.mcrun.config.ServerInstallConfig;
import org.strassburger.mcrun.steps.ServerInstallStep;
import org.strassburger.mcrun.steps.Step;
import org.strassburger.mcrun.steps.StepExecutionException;
import java.io.File;
@Mojo(name = "install")
public class InstallServerMojo extends AbstractMojo {
/**
* Path to the plugin jar to deploy. Defaults to the project's build output jar.
* Override if your jar is assembled elsewhere or has a classifier.
*/
@Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.jar")
private File pluginJar;
/**
* Directory where the test server will be created and run.
* The server jar, plugins folder, and all generated files (eula.txt, world, logs, etc.)
* will be placed here. Defaults to <code>${project.basedir}/server</code>.
*/
@Parameter(defaultValue = "${project.basedir}/server")
private File serverDirectory;
/**
* File name for the downloaded or provided server jar, relative to {@code serverDirectory}.
* Defaults to <code>server.jar</code>.
*/
@Parameter(defaultValue = "server.jar")
private String serverJarName;
/**
* The server software to download. Defaults to <code>paper</code>.
* Can be one <code>paper</code> or <code>spigot</code>.
*/
@Parameter(defaultValue = "paper")
private String serverSoftware;
/**
* When {@code true}, automatically creates {@code eula.txt} with {@code eula=true}
* in the server directory if it does not already exist, bypassing the manual
* acceptance step. Defaults to {@code false}.
*
* <p>By setting this to {@code true} you are indicating that you accept the
* <a href="https://aka.ms/MinecraftEULA">Minecraft End User License Agreement</a>.</p>
*/
@Parameter(defaultValue = "false")
private boolean acceptEula;
/**
* The Minecraft version to run, e.g. <code>1.21.4</code>. Required.
*/
@Parameter(required = true)
private String mcVersion;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Step<?> step = new ServerInstallStep(getLog(),
new ServerInstallConfig(serverDirectory, pluginJar, serverJarName, serverSoftware, mcVersion, acceptEula)
);
try {
step.run();
} catch (StepExecutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
@@ -0,0 +1,95 @@
package org.strassburger.mcrun;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.strassburger.mcrun.config.ServerRunStepConfig;
import org.strassburger.mcrun.steps.ServerRunStep;
import org.strassburger.mcrun.steps.Step;
import org.strassburger.mcrun.steps.StepExecutionException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Mojo(name = "run")
public class RunServerMojo extends AbstractMojo {
/**
* Heap size passed to both {@code -Xmx} and {@code -Xms}.
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>512M</code>.
* Defaults to <code>2G</code>.
*/
@Parameter(defaultValue = "2G")
private String memory;
/**
* Additional JVM arguments to pass to the server process.
* These are inserted after -Xmx/-Xms and before -jar.
*
* <pre>{@code
* <jvmArgs>
* <arg>-XX:+UseG1GC</arg>
* <arg>-XX:+ParallelRefProcEnabled</arg>
* </jvmArgs>
* }</pre>
*/
@Parameter
private List<String> jvmArgs = new ArrayList<>();
/**
* Whether to start the server with JDWP remote debugging enabled.
* When set to <code>true</code>, the JVM is launched with:
* <code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}</code>.
* Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature.
* Defaults to <code>false</code>.
*/
@Parameter(defaultValue = "false")
private boolean remoteDebug;
/**
* The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled.
* Defaults to <code>5005</code>.
*
* <pre>{@code
* <remoteDebug>true</remoteDebug>
* <debugPort>5005</debugPort>
* }</pre>
*/
@Parameter(defaultValue = "5005")
private int debugPort;
/**
* The port the Minecraft server will listen on. Passed to the server via --port.
*/
@Parameter
private Integer port;
/**
* Directory where the test server will be created and run.
* The server jar, plugins folder, and all generated files (eula.txt, world, logs, etc.)
* will be placed here. Defaults to <code>${project.basedir}/server</code>.
*/
@Parameter(defaultValue = "${project.basedir}/server")
private File serverDirectory;
/**
* File name for the downloaded or provided server jar, relative to {@code serverDirectory}.
* Defaults to <code>server.jar</code>.
*/
@Parameter(defaultValue = "server.jar")
private String serverJarName;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Step<?> step = new ServerRunStep(getLog(),
new ServerRunStepConfig(memory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName)
);
try {
step.run();
} catch (StepExecutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
@@ -88,9 +88,25 @@ public class StartServerMojo extends AbstractMojo {
@Parameter
private List<String> jvmArgs = new ArrayList<>();
/**
* Whether to start the server with JDWP remote debugging enabled.
* When set to <code>true</code>, the JVM is launched with:
* <code>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:{debugPort}</code>.
* Attach your IDE's remote debugger to the configured {@code debugPort} to use this feature.
* Defaults to <code>false</code>.
*/
@Parameter(defaultValue = "false")
private boolean remoteDebug;
/**
* The port the JDWP remote debugger will listen on when {@code remoteDebug} is enabled.
* Defaults to <code>5005</code>.
*
* <pre>{@code
* <remoteDebug>true</remoteDebug>
* <debugPort>5005</debugPort>
* }</pre>
*/
@Parameter(defaultValue = "5005")
private int debugPort;