First commit of new Gradle based version
This commit is contained in:
92
build.gradle
Normal file
92
build.gradle
Normal file
@@ -0,0 +1,92 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.gradleup.shadow' version '9.0.0-beta12'
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDirs = ['src']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'dev.rsems.treesize.j.Main'
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveBaseName = 'treesize'
|
||||
archiveClassifier = ''
|
||||
archiveVersion = ''
|
||||
}
|
||||
|
||||
// --- jpackage-based native image ---
|
||||
|
||||
def jpackageOutputDir = layout.buildDirectory.dir('jpackage')
|
||||
def nativeOutputDir = layout.buildDirectory.dir('native')
|
||||
|
||||
tasks.register('jpackageImage', Exec) {
|
||||
dependsOn shadowJar
|
||||
group = 'distribution'
|
||||
description = 'Creates a self-contained native application image using jpackage'
|
||||
|
||||
def inputDir = shadowJar.destinationDirectory
|
||||
def outputDir = jpackageOutputDir.get().asFile
|
||||
|
||||
doFirst {
|
||||
delete outputDir
|
||||
outputDir.mkdirs()
|
||||
}
|
||||
|
||||
commandLine 'jpackage',
|
||||
'--type', 'app-image',
|
||||
'--name', 'treesize',
|
||||
'--input', inputDir.get().asFile.absolutePath,
|
||||
'--main-jar', 'treesize.jar',
|
||||
'--main-class', 'dev.rsems.treesize.j.Main',
|
||||
'--dest', outputDir.absolutePath,
|
||||
'--java-options', '-Xmx512m'
|
||||
}
|
||||
|
||||
tasks.register('nativeBinary', Copy) {
|
||||
dependsOn jpackageImage
|
||||
group = 'distribution'
|
||||
description = 'Copies the self-contained native binary to build/native/treesize'
|
||||
|
||||
def outputDir = nativeOutputDir.get().asFile
|
||||
|
||||
doFirst {
|
||||
outputDir.mkdirs()
|
||||
}
|
||||
|
||||
from(jpackageOutputDir.get().asFile.absolutePath + '/treesize') {
|
||||
include '**/*'
|
||||
}
|
||||
into outputDir.absolutePath + '/treesize'
|
||||
}
|
||||
|
||||
tasks.register('dist') {
|
||||
dependsOn shadowJar, nativeBinary
|
||||
group = 'distribution'
|
||||
description = 'Builds both treesize.jar and the native treesize binary'
|
||||
|
||||
doLast {
|
||||
println ''
|
||||
println '=== Build Complete ==='
|
||||
println "Fat JAR: ${shadowJar.archiveFile.get().asFile.absolutePath}"
|
||||
println "Native image: ${nativeOutputDir.get().asFile.absolutePath}/treesize/"
|
||||
println "Native binary: ${nativeOutputDir.get().asFile.absolutePath}/treesize/bin/treesize"
|
||||
println ''
|
||||
println 'Usage:'
|
||||
println ' java -jar build/libs/treesize.jar # Run via JAR'
|
||||
println ' build/native/treesize/bin/treesize # Run native binary'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user