plugins {
    id 'java'
    id 'application'
}

group = 'io.easystartup'
version = '1.0'

sourceCompatibility = 21
targetCompatibility = 21

repositories {
    mavenCentral()
    google()
    gradlePluginPortal()
}

dependencies {
    implementation group: 'commons-io', name: 'commons-io', version: '2.15.1'
    implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1'
    implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.16.1'

    implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.14.0'
    implementation group: 'commons-net', name: 'commons-net', version: '3.10.0'

    implementation "me.tomsdevsn:hetznercloud-api:3.2.4"

    implementation group: 'com.hubspot.jinjava', name: 'jinjava', version: '2.7.1'

    implementation group: 'net.i2p.crypto', name: 'eddsa', version: '0.3.0'
    implementation group: 'org.apache.sshd', name: 'sshd-core', version: '2.11.0'
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.11'

    implementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.11'


    // Command line arg processor
    implementation 'info.picocli:picocli:4.7.5'
    annotationProcessor 'info.picocli:picocli-codegen:4.7.5'

    testImplementation platform('org.junit:junit-bom:5.9.1')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
    useJUnitPlatform()
}

jar {
    archiveFileName = 'k3s-simplified.jar'
    duplicatesStrategy = "exclude"
    archiveClassifier = "all"
    manifest {
        attributes(
                'Main-Class': 'io.easystartup.Main'
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

// Task to create a tar.gz archive
task createTar(type: Tar) {
    dependsOn jar // This specifies that the jar task must run before createTar

    // Configure the tar task
    compression Compression.GZIP
    archiveFileName = 'k3s-simplified.tar.gz'
    destinationDirectory = file("${buildDir}/distributions")

    // Specify the contents of the tar archive
    from(jar.archiveFile) { // Include the jar file
        into 'k3s-simplified/'
    }
    from("scripts/") { // Include runtime classpath
        into 'k3s-simplified/'
    }
}

application {
    mainClass = 'io.easystartup.Main'
}


//graalvmNative {
//    binaries.all {
//        resources.autodetect()
//    }
//    binaries {
//        main {
//            javaLauncher = javaToolchains.launcherFor {
//                languageVersion = JavaLanguageVersion.of(21)
//                vendor = JvmVendorSpec.matching("GraalVM")
//            }
//            useFatJar = true
//            buildArgs(
//                    "--initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder,org.slf4j.LoggerFactory,org.slf4j.helpers.Reporter,org.slf4j.simple.SimpleLogger",
//                    "-H:ReflectionConfigurationFiles=../../../reflect-config.json",
//                    "-H:+UnlockExperimentalVMOptions",
//                    "--enable-url-protocols=https"
////                    "--features=io.easystartup.Main.RuntimeReflectionRegistrationFeature"
//
//            )
//        }
//    }
//    toolchainDetection = false
//}