|
| 1 | +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 2 | +import org.graalvm.buildtools.gradle.dsl.NativeImageOptions |
| 3 | + |
| 4 | +plugins { |
| 5 | + id 'info.ankin.projects.app-conventions' |
| 6 | +} |
| 7 | + |
| 8 | +version = '0.0.1' |
| 9 | + |
| 10 | +dependencies { |
| 11 | + implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2' |
| 12 | +} |
| 13 | + |
| 14 | +// for shadowJar |
| 15 | +application.mainClass.set 'info.ankin.projects.cli.yaml2json.Yaml2Json' |
| 16 | + |
| 17 | +shadowJar { |
| 18 | + // output first jar as "shadow" |
| 19 | + // so as not to confuse with yaml2json and json2Yaml |
| 20 | + archiveBaseName.set 'shadow' |
| 21 | +} |
| 22 | + |
| 23 | +void customShadowJar(ShadowJar s, String name, String className) { |
| 24 | + s.group 'shadow' |
| 25 | + s.description name + 'Jar shadow jar' |
| 26 | + s.archiveBaseName.set name |
| 27 | + s.manifest { |
| 28 | + attributes('Main-Class': 'info.ankin.projects.cli.yaml2json.' + className) |
| 29 | + } |
| 30 | + s.from zipTree(tasks.shadowJar.getArchiveFile()) |
| 31 | +} |
| 32 | + |
| 33 | +def yaml2JsonJar = tasks.register('yaml2JsonJar', ShadowJar) { |
| 34 | + customShadowJar(it, 'yaml2Json', 'Yaml2Json') |
| 35 | +} |
| 36 | + |
| 37 | +def json2YamlJar = tasks.register('json2YamlJar', ShadowJar) { |
| 38 | + customShadowJar(it, 'json2Yaml', 'Json2Yaml') |
| 39 | +} |
| 40 | + |
| 41 | +tasks { |
| 42 | + shadowJar { |
| 43 | + finalizedBy yaml2JsonJar, json2YamlJar |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +task example { |
| 48 | + doLast { |
| 49 | + println |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +// for graalvmNative |
| 54 | +tasks.jar.enabled(true) |
| 55 | + |
| 56 | +// https://graalvm.github.io/native-build-tools/0.9.11/gradle-plugin.html#_configuration_options |
| 57 | +graalvmNative { |
| 58 | + binaries { |
| 59 | + json2yaml { NativeImageOptions o -> |
| 60 | + o.imageName.set 'json2yaml' |
| 61 | + o.mainClass.set json2YamlJar.get().getManifest().getAttributes().get('Main-Class') |
| 62 | + |
| 63 | + o.debug.set false |
| 64 | + o.verbose.set true |
| 65 | + o.fallback.set false |
| 66 | + o.buildArgs.add('-Ob') // faster development builds |
| 67 | + o.useFatJar.set false |
| 68 | + o.classpath sourceSets.main.output.files, project.tasks.shadowJar |
| 69 | + } |
| 70 | + |
| 71 | + yaml2json { NativeImageOptions o -> |
| 72 | + o.imageName.set 'yaml2json' |
| 73 | + o.mainClass.set yaml2JsonJar.get().getManifest().getAttributes().get('Main-Class') |
| 74 | + o.debug.set false |
| 75 | + o.verbose.set true |
| 76 | + o.fallback.set false |
| 77 | + o.buildArgs.add('-Ob') // faster development builds |
| 78 | + o.useFatJar.set false |
| 79 | + o.classpath sourceSets.main.output.files, project.tasks.shadowJar |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +tasks { |
| 85 | + nativeCompile { |
| 86 | + dependsOn nativeYaml2jsonCompile, nativeJson2yamlCompile |
| 87 | + doLast { |
| 88 | + copy { |
| 89 | + from tasks.nativeJson2yamlCompile.outputs.files.files |
| 90 | + from tasks.nativeYaml2jsonCompile.outputs.files.files |
| 91 | + |
| 92 | + into tasks.nativeCompile.outputs.files.singleFile |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments