//file:noinspection SpellCheckingInspection
//file:noinspection DependencyNotationArgument
plugins {
    id 'java'
    // https://github.com/JetBrains/intellij-platform-gradle-plugin
    // https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin.html
    id 'org.jetbrains.intellij.platform' version '2.5.0'
}

group 'com.acme'
version '0.8.6'

repositories {
    mavenCentral()
    intellijPlatform {
        defaultRepositories()
        marketplace()
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

ext {
    auth0Version = '4.5.0'
    hutoolVersion = '5.8.37'
    jacksonVersion = '2.19.0'
    apachePoiVersion = '5.4.1'
    jsonRepairVersion = '0.3.0'
    fastjson2Version = '2.0.57'
}

dependencies {
    /* BOM依赖 */
    implementation platform("cn.hutool:hutool-bom:${hutoolVersion}")
    implementation platform("com.fasterxml.jackson:jackson-bom:${jacksonVersion}")
    /* IntelliJ 平台依赖 */
    intellijPlatform {
        intellijIdeaCommunity '2025.1'
        bundledPlugin 'org.toml.lang'
        bundledPlugin 'com.intellij.java'
        bundledPlugin 'com.intellij.gradle'
        bundledPlugin 'com.intellij.properties'
        bundledPlugin 'com.intellij.modules.json'
        bundledPlugin 'org.jetbrains.plugins.yaml'
    }
    /* hutool */
    implementation "cn.hutool:hutool-core"
    implementation "cn.hutool:hutool-http"
    /* jackson */
    implementation "com.fasterxml.jackson.core:jackson-databind"
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-csv"
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml"
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-toml"
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"
    implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-properties"
    /* 非BOM依赖 */
    implementation "com.auth0:java-jwt:${auth0Version}"
    implementation "org.apache.poi:poi-ooxml:${apachePoiVersion}"
    implementation "io.github.haibiiin:json-repair:${jsonRepairVersion}"
    implementation "com.alibaba.fastjson2:fastjson2:${fastjson2Version}"
}

runIde {
    // jvm参数优化
    jvmArgs += [
            "-Xms1g",
            "-Xmx4g",
            "-Xshare:off",
            "-Dfile.encoding=UTF-8",
            "-Duser.timezone=GMT+8",
            // 其他优化
            "-XX:+UseParallelGC",
            "-Didea.wsl.disable=true",
            "-XX:ReduceInitialCardSetAllocation=10",
            // 启用模块拓展
            "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
            "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
            "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
            "--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
    ]
    // 设置主题
    systemProperty 'idea.ui.themes', 'Darcula'
    // 设置编码
    systemProperty 'file.encoding', 'UTF-8'
    systemProperty 'idea.encoding.charset', 'UTF-8'
    // 设置插件开发模式
    systemProperty 'idea.is.internal', 'true'
    systemProperty 'idea.auto.update', 'false'
    systemProperty 'idea.dynamic.classpath', 'true'
    systemProperty 'idea.accelerator.manager', 'true'
    systemProperty 'idea.inspections.enabled', 'false'
    systemProperty 'idea.plugins.developer.mode', 'true'
    systemProperty 'idea.plugins.developer.mode.debug', 'true'
}

tasks.register('printVersion') {
    doLast {
        println project.version
    }
}

tasks.register('printJavaVersion') {
    doLast {
        println java.sourceCompatibility
    }
}

tasks.register('printGradleVersion') {
    doLast {
        println gradle.gradleVersion
    }
}

tasks.register('printAllVersions') {
    doLast {
        println "Project Version: ${project.version}"
        println "Java Version: ${java.sourceCompatibility}"
        println "Gradle Version: ${gradle.gradleVersion}"
    }
}

tasks.withType(JavaCompile).configureEach {
    options.fork = true
    options.incremental = true
    options.compilerArgs += ['-Xdoclint:none', '-Xlint:none', '-nowarn']
}