Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ updateDaemonJvm {
}

def jlink = tasks.register('jlink', JlinkTask) {
options = ['--strip-debug', '--no-header-files', '--no-man-pages']
options = ['--strip-debug', '--no-header-files', '--no-man-pages', '--ignore-modified-runtime']
modules = [
'java.instrument', // for junit
'java.naming', // for logback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import javax.inject.Inject;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

public abstract class JlinkTask extends DefaultTask {
Expand Down Expand Up @@ -63,49 +62,35 @@ public JlinkTask(ProjectLayout layout, JavaToolchainService javaToolchain) {
public void createJre() {
var installationPath = getJavaCompiler().get().getMetadata().getInstallationPath();

var jlink = installationPath.file("bin/jlink");
var jmods = installationPath.dir("jmods");
var jlink = installationPath.file("bin/jlink").getAsFile();
var jmods = installationPath.dir("jmods").getAsFile();

var jlinkOutput = getOutputDirectory().dir("jre").get().getAsFile();
getFs().delete(deleteSpec -> deleteSpec.delete(jlinkOutput));

var stdout = new ByteArrayOutputStream();
var stderr = new ByteArrayOutputStream();

var result = getExec().exec(execSpec -> {
execSpec.setIgnoreExitValue(true);

var commandLine = new ArrayList<String>();
commandLine.add(jlink.toString());
commandLine.addAll(getOptions().get());
execSpec.setCommandLine(jlink.getAbsolutePath());
execSpec.args(getOptions().get());

if (getIncludeModulePath().get()) {
commandLine.add("--module-path");
commandLine.add(jmods.toString());
execSpec.args("--module-path", jmods.getAbsolutePath());
}
commandLine.add("--add-modules");
commandLine.add(String.join(",", getModules().get()));
commandLine.add("--output");
commandLine.add(jlinkOutput.toString());

execSpec.setCommandLine(commandLine);
execSpec.args("--add-modules", String.join(",", getModules().get()));
execSpec.args("--output", jlinkOutput.getAbsolutePath());

execSpec.setStandardOutput(stdout);
execSpec.setErrorOutput(stderr);
execSpec.setErrorOutput(stdout);
});

var stdoutStr = stdout.toString();
var stderrStr = stderr.toString();

if (!stdoutStr.isEmpty()) {
getLogger().info(stdoutStr);
}

if (result.getExitValue() != 0) {
if (stderrStr.isEmpty()) {
getLogger().log(LogLevel.ERROR, "jlink failed with exit code: {}", result.getExitValue());
} else {
getLogger().log(LogLevel.ERROR, stderrStr);
}
var level = result.getExitValue() == 0 ? LogLevel.INFO : LogLevel.ERROR;
getLogger().log(level, stdoutStr);
}

result.assertNormalExitValue();
Expand Down
Loading