Skip to content

Commit 647f849

Browse files
Jlink task improvements (#413)
1 parent c415768 commit 647f849

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ updateDaemonJvm {
4141
}
4242

4343
def jlink = tasks.register('jlink', JlinkTask) {
44-
options = ['--strip-debug', '--no-header-files', '--no-man-pages']
44+
options = ['--strip-debug', '--no-header-files', '--no-man-pages', '--ignore-modified-runtime']
4545
modules = [
4646
'java.instrument', // for junit
4747
'java.naming', // for logback

buildSrc/src/main/java/com/github/stickerifier/stickerify/JlinkTask.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import javax.inject.Inject;
2121
import java.io.ByteArrayOutputStream;
22-
import java.util.ArrayList;
2322
import java.util.List;
2423

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

66-
var jlink = installationPath.file("bin/jlink");
67-
var jmods = installationPath.dir("jmods");
65+
var jlink = installationPath.file("bin/jlink").getAsFile();
66+
var jmods = installationPath.dir("jmods").getAsFile();
6867

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

7271
var stdout = new ByteArrayOutputStream();
73-
var stderr = new ByteArrayOutputStream();
7472

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

78-
var commandLine = new ArrayList<String>();
79-
commandLine.add(jlink.toString());
80-
commandLine.addAll(getOptions().get());
76+
execSpec.setCommandLine(jlink.getAbsolutePath());
77+
execSpec.args(getOptions().get());
78+
8179
if (getIncludeModulePath().get()) {
82-
commandLine.add("--module-path");
83-
commandLine.add(jmods.toString());
80+
execSpec.args("--module-path", jmods.getAbsolutePath());
8481
}
85-
commandLine.add("--add-modules");
86-
commandLine.add(String.join(",", getModules().get()));
87-
commandLine.add("--output");
88-
commandLine.add(jlinkOutput.toString());
8982

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

9286
execSpec.setStandardOutput(stdout);
93-
execSpec.setErrorOutput(stderr);
87+
execSpec.setErrorOutput(stdout);
9488
});
9589

9690
var stdoutStr = stdout.toString();
97-
var stderrStr = stderr.toString();
98-
9991
if (!stdoutStr.isEmpty()) {
100-
getLogger().info(stdoutStr);
101-
}
102-
103-
if (result.getExitValue() != 0) {
104-
if (stderrStr.isEmpty()) {
105-
getLogger().log(LogLevel.ERROR, "jlink failed with exit code: {}", result.getExitValue());
106-
} else {
107-
getLogger().log(LogLevel.ERROR, stderrStr);
108-
}
92+
var level = result.getExitValue() == 0 ? LogLevel.INFO : LogLevel.ERROR;
93+
getLogger().log(level, stdoutStr);
10994
}
11095

11196
result.assertNormalExitValue();

0 commit comments

Comments
 (0)