// 编译脚本
buildscript {
    ext {
        // https://start.spring.io/actuator/info
        springBootVersion = "3.5.6"
        mybatisPlusVersion = "3.5.14"
        springdocVersion = "2.8.13"
        jakartaServletApiVersion = "6.1.0"
        postgresqlVersion = "42.7.8"
        bcprovJdk18onVersion = "1.82"
        kissoVersion = "3.9.5"
    }

    // 仓库配置
    repositories {
        mavenLocal()
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/spring' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("com.vanniktech:gradle-maven-publish-plugin:0.32.0")
    }
}

description = "爱组搭低代码组件化开发平台"

// 项目配置
allprojects {
    group APP_GROUP
    version APP_VERSION
}

// 子模块配置
subprojects {
    apply plugin: 'java-library'
    apply plugin: 'com.vanniktech.maven.publish'
    apply plugin: 'signing'
    apply plugin: 'io.spring.dependency-management'

    // 仓库配置
    repositories {
        mavenLocal()
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/spring' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        mavenCentral()
    }

    configurations {
        all*.exclude group: "ch.qos.logback"
        all*.exclude module: "spring-boot-starter-logging"
        // 使用Undertow 替代Tomcat
        all*.exclude group: "org.apache.tomcat"
        all*.exclude group: "org.apache.tomcat.embed"
        all*.exclude module: "spring-boot-starter-tomcat"
    }

    // 依赖管理
    dependencyManagement {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
        }
    }

    // 依赖配置
    dependencies {
        compileOnly("org.projectlombok:lombok")
        annotationProcessor("org.projectlombok:lombok")
        testAnnotationProcessor("org.projectlombok:lombok")
        testCompileOnly("org.projectlombok:lombok")
        // 为了减少依赖 jar 体量，非公共依赖不要申明为 api 必须遵守在负责人同意允许后在对应项目中添加

        compileOnly("org.springframework.boot:spring-boot-starter-log4j2")
        compileOnly("jakarta.servlet:jakarta.servlet-api:${jakartaServletApiVersion}")
        compileOnly("org.aspectj:aspectjweaver")

        // 编译测试
        testImplementation("org.springframework.boot:spring-boot-starter-test")
    }

    // 编译环境 JDK-17+
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17

    tasks.named('test') {
        useJUnitPlatform()
    }

    tasks.withType(JavaCompile).configureEach {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:-serial"
        options.encoding = 'UTF-8'
        options.warnings = false
        options.deprecation = true
        options.compilerArgs += ["-parameters"]
    }

    tasks.withType(GenerateModuleMetadata).configureEach {
        enabled = false
    }

    tasks.register('sourcesJar', Jar) {
        dependsOn classes
        archiveClassifier = 'sources'
        from sourceSets.main.allSource
    }

    javadoc {
        options {
            encoding "UTF-8"
            charSet 'UTF-8'
            author true
            version true
            failOnError false
            links "https://docs.oracle.com/javase/8/docs/api"
        }
    }

    tasks.withType(MavenPublication).configureEach {
        doFirst {
            options.skipCertificateChecks = true
        }
    }

    tasks.register('javadocJar', Jar) {
        archiveClassifier = 'javadoc'
        from javadoc
    }
}
