plugins {
    id 'java'
    id 'application'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'com.github.ben-manes.versions' version '0.49.0'
}

group = 'com.github.fabienrenaud'
version = '8'
mainClassName = 'com.github.fabienrenaud.jjb.Cli'

sourceCompatibility = 17
targetCompatibility = 17

repositories {
    mavenCentral()
}

ext {
    avajeJsonVersion = '1.11'
    jacksonVersion = '2.17.1'
    dslJsonVersion = '2.0.2'
    johnzonVersion = '2.0.1'
    jmhVersion = '1.35'
}

dependencies {

    // CLI and misc
    implementation group: 'io.airlift', name: 'airline', version: '0.9'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

    // JSON libraries
    // In alphabetical order.

    // antons
    implementation group: 'io.github.antonsjava', name: 'json', version: '1.17'
    // avaje-jsonb
    implementation group: 'io.avaje', name: 'avaje-jsonb', version: "${avajeJsonVersion}"
    implementation group: 'io.avaje', name: 'avaje-jsonb-jackson', version: "${avajeJsonVersion}"
    annotationProcessor group: 'io.avaje', name: 'avaje-jsonb-generator', version: "${avajeJsonVersion}"   
    // boon
    implementation group: 'io.fastjson', name: 'boon', version: '0.34'
    // DSL-json
    implementation group: 'com.dslplatform', name: 'dsl-json', version: "${dslJsonVersion}"
    annotationProcessor group: 'com.dslplatform', name: 'dsl-json', version: "${dslJsonVersion}"
    // FastJson
    implementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.57'
    // FlexJson
    implementation group: 'net.sf.flexjson', name: 'flexjson', version: '3.3'
    // GENSON
    implementation group: 'com.owlike', name: 'genson', version: '1.6'
    // GSON
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.11.0'
    // Jackson
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}"
    implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner', version: "${jacksonVersion}"
    implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-blackbird', version: "${jacksonVersion}"
    implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: "${jacksonVersion}"
    // jodd
    implementation group: 'org.jodd', name: 'jodd-json', version: '6.0.3'
    // johnzon
    implementation group: 'org.apache.johnzon', name: 'johnzon-core', version: "${johnzonVersion}"
    implementation group: 'org.apache.johnzon', name: 'johnzon-mapper', version: "${johnzonVersion}"
    // Jakarta
    implementation group: 'jakarta.json.bind', name: 'jakarta.json.bind-api', version: '3.0.1'
    implementation group: 'jakarta.json', name: 'jakarta.json-api', version: '2.1.3'
    implementation group: 'org.glassfish', name: 'jakarta.json', version: '2.0.1'
    // json-io
    implementation group: 'com.cedarsoftware', name: 'json-io', version: '4.24.0'
    // json-simple
    implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    // json-smart
    implementation group: 'net.minidev', name: 'json-smart', version: '2.5.1'
    // LoganSquare
    implementation group: 'com.bluelinelabs', name: 'logansquare', version: '1.3.7'
    annotationProcessor group: 'com.bluelinelabs', name: 'logansquare-compiler', version: '1.3.7'
    // minimal-json
    implementation group: 'com.eclipsesource.minimal-json', name: 'minimal-json', version: '0.9.5'
    // mjson
    implementation group: 'org.sharegov', name: 'mjson', version: '1.4.1'
    // moshi
    implementation group: 'com.squareup.moshi', name: 'moshi', version: '1.15.1'
    // nanojson
    implementation group: 'com.grack', name: 'nanojson', version: '1.9'
    // org.json
    implementation group: 'org.json', name: 'json', version: '20240303'
    // purejson
    implementation group: 'io.github.senthilganeshs', name: 'purejson', version: '1.0.1'
    // qson
    implementation group: 'io.quarkus.qson', name: 'qson-generator', version: '1.1.1.Final'
    // tapestry
    implementation group: 'org.apache.tapestry', name: 'tapestry-json', version: '5.8.6'
    // underscore-java
    implementation group: 'com.github.javadev', name: 'underscore', version: '1.101'
    // yasson
    implementation group: 'org.eclipse', name: 'yasson', version: '3.0.3'
    // QuickBuffers
    implementation group: 'us.hebi.quickbuf', name: 'quickbuf-runtime', version: '1.4'
    // wast
    implementation group: 'io.github.wycst', name: 'wast', version: '0.0.26'

    // Test
    testImplementation group: 'junit', name: 'junit', version: '4.13.2'

    // IMPORTANT: Leave JMH at the end!
    // JMH
    implementation group: 'org.openjdk.jmh', name: 'jmh-core', version: "${jmhVersion}"
    annotationProcessor group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: "${jmhVersion}"
}

shadowJar {
    archiveFileName = 'app.jar'
    exclude 'META-INF/*.SF'
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}

test {
    jvmArgs '--add-opens=java.base/java.time=ALL-UNNAMED --add-modules=jdk.incubator.vector'
    testLogging {
        exceptionFormat = 'full'
        showStandardStreams = true
    }
}

task (depsize) {
    doLast {
        def size = 0
        def formatStr = '%,10.2f'
        configurations.default.collect { it.length() / (1024 * 1024) }.each { size += it }

        def out = new StringBuffer()
        out << 'Total dependencies size:'.padRight(45)
        out << "${String.format(formatStr, size)} MiB\n\n"

        configurations
            .default
            .sort { -it.length() }
            .each {
                out << "${it.name}".padRight(45)
                out << "${String.format(formatStr, (it.length() / 1024))} KiB\n"
            }
            println(out)
    }
}
