Split up memory option to min and maxmemory

This commit is contained in:
2026-05-24 22:35:43 +02:00
parent b9e49b387f
commit 8e08154d21
5 changed files with 29 additions and 12 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<groupId>org.strassburger</groupId> <groupId>org.strassburger</groupId>
<artifactId>mcrun-maven-plugin</artifactId> <artifactId>mcrun-maven-plugin</artifactId>
<version>0.0.15</version> <version>0.0.16</version>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<name>MCRun Maven Plugin</name> <name>MCRun Maven Plugin</name>
@@ -17,12 +17,20 @@ import java.util.List;
@Mojo(name = "run") @Mojo(name = "run")
public class RunServerMojo extends AbstractMojo { public class RunServerMojo extends AbstractMojo {
/** /**
* Heap size passed to both {@code -Xmx} and {@code -Xms}. * Minimum heap size passed to {@code -Xms}.
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>512M</code>. * Accepts standard JVM memory notation, e.g. <code>512M</code>, <code>1G</code>.
* Defaults to <code>512M</code>.
*/
@Parameter(defaultValue = "512M")
private String minMemory;
/**
* Maximum heap size passed to {@code -Xmx}.
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>4G</code>.
* Defaults to <code>2G</code>. * Defaults to <code>2G</code>.
*/ */
@Parameter(defaultValue = "2G") @Parameter(defaultValue = "2G")
private String memory; private String maxMemory;
/** /**
* Additional JVM arguments to pass to the server process. * Additional JVM arguments to pass to the server process.
@@ -84,7 +92,7 @@ public class RunServerMojo extends AbstractMojo {
@Override @Override
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
Step<?> step = new ServerRunStep(getLog(), Step<?> step = new ServerRunStep(getLog(),
new ServerRunStepConfig(memory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName) new ServerRunStepConfig(minMemory, maxMemory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName)
); );
try { try {
step.run(); step.run();
@@ -56,12 +56,20 @@ public class StartServerMojo extends AbstractMojo {
private String mcVersion; private String mcVersion;
/** /**
* Heap size passed to both {@code -Xmx} and {@code -Xms}. * Minimum heap size passed to {@code -Xms}.
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>512M</code>. * Accepts standard JVM memory notation, e.g. <code>512M</code>, <code>1G</code>.
* Defaults to <code>512M</code>.
*/
@Parameter(defaultValue = "512M")
private String minMemory;
/**
* Maximum heap size passed to {@code -Xmx}.
* Accepts standard JVM memory notation, e.g. <code>2G</code>, <code>4G</code>.
* Defaults to <code>2G</code>. * Defaults to <code>2G</code>.
*/ */
@Parameter(defaultValue = "2G") @Parameter(defaultValue = "2G")
private String memory; private String maxMemory;
/** /**
* When {@code true}, automatically creates {@code eula.txt} with {@code eula=true} * When {@code true}, automatically creates {@code eula.txt} with {@code eula=true}
@@ -133,7 +141,7 @@ public class StartServerMojo extends AbstractMojo {
new ServerInstallConfig(serverDirectory, pluginJar, serverJarName, serverSoftware, mcVersion, acceptEula) new ServerInstallConfig(serverDirectory, pluginJar, serverJarName, serverSoftware, mcVersion, acceptEula)
)); ));
steps.add(new ServerRunStep(getLog(), steps.add(new ServerRunStep(getLog(),
new ServerRunStepConfig(memory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName) new ServerRunStepConfig(minMemory, maxMemory, jvmArgs, remoteDebug, debugPort, port, serverDirectory, serverJarName)
)); ));
return steps; return steps;
} }
@@ -3,7 +3,8 @@ package org.strassburger.mcrun.config;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
public record ServerRunStepConfig(String memory, public record ServerRunStepConfig(String minMemory,
String maxMemory,
List<String> jvmArgs, List<String> jvmArgs,
boolean remoteDebug, boolean remoteDebug,
int debugPort, int debugPort,
@@ -20,8 +20,8 @@ public class ServerRunStep extends Step<ServerRunStepConfig> {
private List<String> buildCommand() { private List<String> buildCommand() {
List<String> cmd = new ArrayList<>(); List<String> cmd = new ArrayList<>();
cmd.add("java"); cmd.add("java");
cmd.add("-Xmx" + getConfig().memory()); cmd.add("-Xmx" + getConfig().maxMemory());
cmd.add("-Xms" + getConfig().memory()); cmd.add("-Xms" + getConfig().minMemory());
if (getConfig().remoteDebug() && getConfig().debugPort() > 0) { if (getConfig().remoteDebug() && getConfig().debugPort() > 0) {
cmd.add(String.format("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:%d", getConfig().debugPort())); cmd.add(String.format("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:%d", getConfig().debugPort()));
} }