|
1 | | -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform |
| 1 | +import org.apache.tools.ant.taskdefs.condition.Os |
2 | 2 |
|
3 | 3 | plugins { |
4 | | - alias(libs.plugins.runtime) |
5 | 4 | alias(libs.plugins.shadow) |
| 5 | + id 'application' |
6 | 6 | id 'java' |
7 | 7 | id 'jacoco' |
8 | 8 | } |
@@ -53,12 +53,53 @@ tasks.withType(JavaCompile).configureEach { |
53 | 53 | options.encoding = 'UTF-8' |
54 | 54 | } |
55 | 55 |
|
| 56 | +def jreOutputDir = layout.buildDirectory.dir('jre') |
| 57 | +tasks.register('jre') { |
| 58 | + inputs.property('options', ['--strip-debug', '--no-header-files', '--no-man-pages']) |
| 59 | + inputs.property('modules', ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported']) |
| 60 | + |
| 61 | + outputs.dir(jreOutputDir) |
| 62 | + |
| 63 | + doFirst { |
| 64 | + delete(jreOutputDir) |
| 65 | + } |
| 66 | + |
| 67 | + def javaLauncher = javaToolchains.launcherFor(java.toolchain) |
| 68 | + |
| 69 | + doLast { |
| 70 | + def installationPath = javaLauncher.get().metadata.installationPath |
| 71 | + |
| 72 | + def jlink = installationPath.file(Os.isFamily(Os.FAMILY_WINDOWS) ? 'bin\\jlink.exe' : 'bin/jlink') |
| 73 | + def jmods = installationPath.dir('jmods') |
| 74 | + |
| 75 | + def output = providers.exec { |
| 76 | + ignoreExitValue = true |
| 77 | + commandLine = [ |
| 78 | + jlink.toString(), '-v', |
| 79 | + *(inputs.properties['options'] as List), |
| 80 | + '--module-path', jmods.toString(), |
| 81 | + '--add-modules', (inputs.properties['modules'] as List).join(','), |
| 82 | + '--output', jreOutputDir.get().toString() |
| 83 | + ] |
| 84 | + } |
| 85 | + |
| 86 | + def result = output.result.get() |
| 87 | + if (result.exitValue == 0) { |
| 88 | + logger.info(output.standardOutput.asText.get()) |
| 89 | + } else { |
| 90 | + logger.log(LogLevel.ERROR, output.standardError.asText.get()) |
| 91 | + } |
| 92 | + |
| 93 | + result.assertNormalExitValue() |
| 94 | + result.rethrowFailure() |
| 95 | + } |
| 96 | +} |
| 97 | + |
56 | 98 | test { |
57 | | - dependsOn jre |
58 | | - inputs.dir tasks.jre.jreDir |
| 99 | + dependsOn tasks.named('jre') |
| 100 | + inputs.dir(jreOutputDir) |
59 | 101 |
|
60 | | - def file = DefaultNativePlatform.currentOperatingSystem.isWindows() ? 'java.exe' : 'java' |
61 | | - executable = tasks.jre.jreDir.file('bin/' + file) |
| 102 | + executable = jreOutputDir.get().file(Os.isFamily(Os.FAMILY_WINDOWS) ? 'bin\\java.exe' : 'bin/java') |
62 | 103 |
|
63 | 104 | useJUnitPlatform() |
64 | 105 | finalizedBy jacocoTestReport |
@@ -93,10 +134,3 @@ shadowJar { |
93 | 134 | exclude('dist_webp_binaries/') |
94 | 135 | } |
95 | 136 | } |
96 | | - |
97 | | -runtime { |
98 | | - options = ['--strip-debug', '--no-header-files', '--no-man-pages'] // don't compress jre because final docker image will be larger |
99 | | - modules = ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported'] |
100 | | -} |
101 | | - |
102 | | -suggestModules.dependsOn shadowJar |
|
0 commit comments