buildscript {
    ext.kotlinVersion = '1.8.10'
    ext.isCI = System.getenv('GITHUB_ACTION')
    repositories {
        gradlePluginPortal()
        mavenCentral()
        if (version.endsWith('SNAPSHOT')) {
            maven { url 'https://repo.spring.io/snapshot' }
        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
    }
}

plugins {
    id 'base'
    id 'io.spring.nohttp' version '0.0.11' apply false
    id 'org.ajoberstar.grgit' version '4.1.1'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'org.jetbrains.dokka' version "$kotlinVersion"
    id 'org.asciidoctor.jvm.pdf' version '3.3.2'
    id 'org.asciidoctor.jvm.convert' version '3.3.2'
    id 'com.github.spotbugs' version '6.0.7'
}

if (isCI) {
    apply plugin: 'io.spring.nohttp'

    nohttp {
        source.include '**/src/**'
        source.exclude '**/bin/**', '**/build/**', '**/out/**', '**/target/**', '**/*.gif', '**/*.jpg', '**/*.png', '**/*.svg', '**/*.ks'
    }
}

description = 'Spring Integration'

ext {
    linkHomepage = 'https://projects.spring.io/spring-integration'
    linkCi = 'https://build.spring.io/browse/INT'
    linkIssue = 'https://github.com/spring-projects/spring-integration/issues'
    linkScmUrl = 'https://github.com/spring-projects/spring-integration'
    linkScmConnection = 'scm:git:git://github.com/spring-projects/spring-integration.git'
    linkScmDevConnection = 'scm:git:ssh://git@github.com:spring-projects/spring-integration.git'

    modifiedFiles =
            files(grgit.status().unstaged.modified).filter { f -> f.name.endsWith('.java') || f.name.endsWith('.kt') }

    apacheSshdVersion = '2.9.2'
    artemisVersion = '2.28.0'
    aspectjVersion = '1.9.20.1'
    assertjVersion = '3.24.2'
    assertkVersion = '0.26.1'
    avroVersion = '1.11.3'
    awaitilityVersion = '4.2.0'
    camelVersion = '3.20.8'
    commonsDbcp2Version = '2.9.0'
    commonsIoVersion = '2.11.0'
    commonsNetVersion = '3.9.0'
    curatorVersion = '5.5.0'
    derbyVersion = '10.16.1.1'
    ftpServerVersion = '1.2.0'
    graalvmVersion = '22.3.4'
    greenmailVersion = '2.0.0'
    groovyVersion = '4.0.15'
    hamcrestVersion = '2.2'
    hazelcastVersion = '5.2.4'
    hibernateVersion = '6.2.13.Final'
    hsqldbVersion = '2.7.2'
    h2Version = '2.2.224'
    jacksonVersion = '2.15.3'
    jaxbVersion = '4.0.4'
    jcifsVersion = '2.1.37'
    jeroMqVersion = '0.5.4'
    jmsApiVersion = '3.1.0'
    jpaApiVersion = '3.1.0'
    jrubyVersion = '9.4.3.0'
    jsonpathVersion = '2.8.0'
    junit4Version = '4.13.2'
    junitJupiterVersion = '5.9.3'
    jythonVersion = '2.7.3'
    kotlinCoroutinesVersion = '1.6.4'
    kryoVersion = '5.5.0'
    lettuceVersion = '6.2.7.RELEASE'
    log4jVersion = '2.20.0'
    mailVersion = '1.0.0'
    micrometerTracingVersion = '1.1.7'
    micrometerVersion = '1.11.9'
    mockitoVersion = '5.3.1'
    mongoDriverVersion = '4.9.1'
    mysqlVersion = '8.0.33'
    oracleVersion = '23.3.0.23.09'
    pahoMqttClientVersion = '1.2.5'
    postgresVersion = '42.6.0'
    protobufVersion = '3.23.4'
    r2dbch2Version = '1.0.0.RELEASE'
    reactorVersion = '2022.0.13'
    resilience4jVersion = '2.0.2'
    romeToolsVersion = '2.1.0'
    rsocketVersion = '1.1.4'
    servletApiVersion = '6.0.0'
    smackVersion = '4.4.6'
    springAmqpVersion = '3.0.10'
    springDataVersion = '2023.0.6'
    springGraphqlVersion = '1.2.4'
    springKafkaVersion = '3.0.13'
    springRetryVersion = '2.0.5'
    springSecurityVersion = '6.1.5'
    springVersion = '6.0.14'
    springWsVersion = '4.0.8'
    testcontainersVersion = '1.19.2'
    tomcatVersion = '10.1.16'
    xmlUnitVersion = '2.9.1'
    xstreamVersion = '1.4.20'
    ztZipVersion = '1.16'

    javaProjects = subprojects - project(':spring-integration-bom')
}

allprojects {
    group = 'org.springframework.integration'

    repositories {
        if (project.hasProperty('mavenLocal')) {
            mavenLocal()
        }
        mavenCentral()
        maven { url 'https://repo.spring.io/milestone' }
        if (version.endsWith('SNAPSHOT')) {
            maven { url 'https://repo.spring.io/snapshot' }
        }
//		maven { url 'https://repo.spring.io/libs-staging-local' }
    }

    ext.javadocLinks = [
            'https://docs.oracle.com/en/java/javase/17/docs/api/',
            'https://jakarta.ee/specifications/platform/10/apidocs/',
            'https://docs.spring.io/spring-framework/docs/current/javadoc-api',
            'https://docs.spring.io/spring-amqp/docs/current/api/',
            'https://docs.spring.io/spring-data/data-mongo/docs/current/api/',
            'https://docs.spring.io/spring-data/data-redis/docs/current/api/',
            'https://docs.spring.io/spring-ws/docs/current/api/'
    ] as String[]

    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        resolutionStrategy {
            cacheChangingModulesFor 0, 'seconds'
        }
        applyMavenExclusions = false
        generatedPomCustomization {
            enabled = false
        }

        imports {
            mavenBom "com.fasterxml.jackson:jackson-bom:$jacksonVersion"
            mavenBom "org.junit:junit-bom:$junitJupiterVersion"
            mavenBom "io.projectreactor:reactor-bom:$reactorVersion"
            mavenBom "org.apache.logging.log4j:log4j-bom:$log4jVersion"
            mavenBom "org.mockito:mockito-bom:$mockitoVersion"
            mavenBom "io.micrometer:micrometer-bom:$micrometerVersion"
            mavenBom "io.micrometer:micrometer-tracing-bom:$micrometerTracingVersion"
            mavenBom "org.apache.camel:camel-bom:$camelVersion"
            mavenBom "org.testcontainers:testcontainers-bom:$testcontainersVersion"
            mavenBom "org.apache.groovy:groovy-bom:$groovyVersion"
            mavenBom "org.springframework.security:spring-security-bom:$springSecurityVersion"
            mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:$kotlinCoroutinesVersion"
            mavenBom "org.springframework.amqp:spring-amqp-bom:$springAmqpVersion"
            mavenBom "org.springframework.kafka:spring-kafka-bom:$springKafkaVersion"
            mavenBom "org.springframework.data:spring-data-bom:$springDataVersion"
            mavenBom "org.springframework:spring-framework-bom:$springVersion"
            mavenBom "org.springframework.ws:spring-ws-bom:$springWsVersion"
        }

    }

}

configure(javaProjects) { subproject ->
    apply plugin: 'java-library'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'checkstyle'
    apply plugin: 'kotlin'
    apply plugin: 'kotlin-spring'

    apply from: "${rootDir}/gradle/publish-maven.gradle"

    sourceSets {
        test {
            resources {
                srcDirs = ['src/test/resources', 'src/test/java']
            }
        }
    }

    java {
        withJavadocJar()
        withSourcesJar()
        registerFeature('optional') {
            usingSourceSet(sourceSets.main)
        }
        registerFeature('provided') {
            usingSourceSet(sourceSets.main)
        }
    }

    compileJava {
        options.release = 17
    }

    compileTestJava {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
        options.encoding = 'UTF-8'
    }

    compileKotlin {
        kotlinOptions {
            languageVersion = '1.7'
            apiVersion = '1.7'
            allWarningsAsErrors = true
        }
    }

    tasks.withType(JavaCompile).configureEach {
        options.fork = true
    }

    tasks.withType(Javadoc) {
        options.addBooleanOption('Xdoclint:syntax', true) // only check syntax with doclint
        options.addBooleanOption('Werror', true) // fail build on Javadoc warnings
    }

    eclipse {
        project {
            natures += 'org.springframework.ide.eclipse.core.springnature'
        }
    }

    // dependencies that are common across all java projects
    dependencies {
        if (!(subproject.name ==~ /.*-test.*/)) {
            testImplementation(project(':spring-integration-test-support')) {
                exclude group: 'org.hamcrest'
            }
        }

        def spotbugsAnnotations = "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}"
        compileOnly spotbugsAnnotations
        testCompileOnly spotbugsAnnotations

        testImplementation("org.awaitility:awaitility:$awaitilityVersion") {
            exclude group: 'org.hamcrest'
        }
        testImplementation("junit:junit:$junit4Version") {
            exclude group: 'org.hamcrest'
        }
        testImplementation 'org.junit.jupiter:junit-jupiter-api'
        testImplementation 'org.junit.jupiter:junit-jupiter-params'
        testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertkVersion") {
            exclude group: 'org.jetbrains.kotlin'
        }
        testImplementation 'org.jetbrains.kotlin:kotlin-reflect'
        testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
        testImplementation 'io.projectreactor:reactor-test'
        testImplementation 'org.testcontainers:junit-jupiter'

        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
        testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
        // To support JUnit 4 tests
        testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

        testRuntimeOnly 'org.apache.logging.log4j:log4j-core'
        testRuntimeOnly 'org.apache.logging.log4j:log4j-jcl'
        testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'
        testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl'
    }

    // enable all compiler warnings; individual projects may customize further
    ext.xLintArg = '-Xlint:all,-options,-processing'
    [compileJava, compileTestJava]*.options*.compilerArgs = [xLintArg, '-parameters']

    task updateCopyrights {
        onlyIf { !isCI }
        inputs.files(modifiedFiles.filter { f -> f.path.contains(subproject.name) })
        outputs.dir('build/classes')

        doLast {
            def now = Calendar.instance.get(Calendar.YEAR) as String
            inputs.files.each { file ->
                def line
                file.withReader { reader ->
                    while (line = reader.readLine()) {
                        def matcher = line =~ /Copyright (20\d\d)-?(20\d\d)?/
                        if (matcher.count) {
                            def beginningYear = matcher[0][1]
                            if (now != beginningYear && now != matcher[0][2]) {
                                def years = "$beginningYear-$now"
                                def sourceCode = file.text
                                sourceCode = sourceCode.replaceFirst(/20\d\d(-20\d\d)?/, years)
                                file.text = sourceCode
                                println "Copyright updated for file: $file"
                            }
                            break
                        }
                    }
                }
            }
        }
    }

    compileKotlin.dependsOn updateCopyrights

    test {
        maxHeapSize = '2g'
        jvmArgs '-XX:+HeapDumpOnOutOfMemoryError'
    }

    task testAll(type: Test, dependsOn: [':checkAsciidocLinks', 'check'])

    gradle.taskGraph.whenReady { graph ->
        if (graph.hasTask(testAll)) {
            test.enabled = false
        }
    }

    tasks.withType(Test).all {
        // suppress all console output during testing unless running `gradle -i`
        logging.captureStandardOutput(LogLevel.INFO)

        if (name ==~ /(testAll)/) {
            systemProperty 'RUN_LONG_INTEGRATION_TESTS', 'true'
        }

        environment 'SI_FATAL_WHEN_NO_BEANFACTORY', 'true'

        useJUnitPlatform()

        enableAssertions = false
    }

    checkstyle {
        configDirectory.set(rootProject.file('src/checkstyle'))
        toolVersion = project.hasProperty('checkstyleVersion') ? project.checkstyleVersion : '10.12.1'
    }

    jar {
        manifest {
            attributes(
                    'Implementation-Version': project.version,
                    'Created-By': "JDK ${System.properties['java.version']} (${System.properties['java.specification.vendor']})",
                    'Implementation-Title': subproject.name,
                    'Implementation-Vendor-Id': subproject.group,
                    'Implementation-Vendor': 'Pivotal Software, Inc.',
                    'Implementation-URL': linkHomepage,
                    'Automatic-Module-Name': subproject.name.replace('-', '.')  // for Jigsaw
            )
        }

        from("${rootProject.projectDir}/src/dist") {
            include 'notice.txt'
            into 'META-INF'
            expand(copyright: new Date().format('yyyy'), version: project.version)
        }
        from("${rootProject.projectDir}") {
            include 'LICENSE.txt'
            into 'META-INF'
        }
    }

    task checkClasspathForConflicts {
        onlyIf { isCI }
        inputs.files(configurations.runtimeClasspath)

        def ignored = ['module-info.class']
        def errors = ['Found classpath conflicts:\n']
        Map<String, Set<String>> classpathContents = [:]

        doLast {
            inputs.files.each { file ->
                new java.util.jar.JarFile(file)
                        .stream()
                        .filter { !it.name.startsWith('META-INF/') && it.name.endsWith('.class') && !ignored.contains(it.name) }
                        .each { classpathContents.computeIfAbsent(it.name, { [] as Set }).add(file.absolutePath) }
            }

            def conflicts = classpathContents.findAll { it.value.size() > 1 }

            conflicts.each {
                errors += "    $it.key\n"
                it.value.each {
                    errors += "        $it\n"
                }
            }

            if (errors.size() > 1) {
                throw new InvalidUserDataException(errors.toString().replaceAll(~/,\s/, '') - '[' - ']')
            }
        }
    }

    check.dependsOn checkClasspathForConflicts, javadoc

    publishing {
        publications {
            mavenJava(MavenPublication) {
                suppressAllPomMetadataWarnings()
                from components.java
                pom.withXml {
                    def pomDeps = asNode().dependencies.first()
                    subproject.configurations.providedImplementation.allDependencies.each { dep ->
                        pomDeps.remove(pomDeps.'*'.find { it.artifactId.text() == dep.name })
                        pomDeps.appendNode('dependency').with {
                            it.appendNode('groupId', dep.group)
                            it.appendNode('artifactId', dep.name)
                            it.appendNode('version', dep.version)
                            it.appendNode('scope', 'provided')
                        }
                    }
                }
            }
        }
    }
}

project('spring-integration-test-support') {
    description = 'Spring Integration Test Support - **No SI Dependencies Allowed**'
    dependencies {
        compileOnly 'org.apiguardian:apiguardian-api:1.0.0'
        api "org.hamcrest:hamcrest-library:$hamcrestVersion"
        api 'org.mockito:mockito-core'
        api "org.assertj:assertj-core:$assertjVersion"
        api 'org.springframework:spring-context'
        api 'org.springframework:spring-messaging'
        api 'org.springframework:spring-test'
        optionalApi("junit:junit:$junit4Version") {
            exclude group: 'org.hamcrest'
        }
        optionalApi 'org.junit.jupiter:junit-jupiter-api'
        optionalApi 'org.apache.logging.log4j:log4j-core'
    }
}

project('spring-integration-amqp') {
    description = 'Spring Integration AMQP Support'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.amqp:spring-rabbit') {
            exclude group: 'org.springframework'
        }
        optionalApi('org.springframework.amqp:spring-rabbit-stream') {
            exclude group: 'org.springframework'
        }

        testImplementation('org.springframework.amqp:spring-rabbit-junit') {
            exclude group: 'org.springframework'
        }
        testImplementation project(':spring-integration-stream')
        testImplementation 'org.springframework:spring-web'
        testImplementation 'org.testcontainers:rabbitmq'
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
    }
}

project('spring-integration-camel') {
    description = 'Spring Integration support for Apache Camel'

    dependencies {
        api project(':spring-integration-core')
        api 'org.apache.camel:camel-core-model'

        testImplementation 'org.apache.camel:camel-test-junit5'
        testImplementation ('org.apache.camel:camel-spring') {
            exclude group: 'org.springframework'
        }
    }
}

project('spring-integration-cassandra') {
    description = 'Spring Integration Support for Apache Cassandra'

    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework.data:spring-data-cassandra'

        testImplementation 'org.testcontainers:cassandra'
    }
}

project('spring-integration-core') {
    description = 'Spring Integration Core'

    apply plugin: 'org.jetbrains.dokka'

    dependencies {
        api 'org.springframework:spring-aop'
        api 'org.springframework:spring-context'
        api 'org.springframework:spring-messaging'
        api 'org.springframework:spring-tx'
        api("org.springframework.retry:spring-retry:$springRetryVersion") {
            exclude group: 'org.springframework'
        }
        api 'io.projectreactor:reactor-core'
        api 'io.micrometer:micrometer-observation'

        optionalApi 'com.fasterxml.jackson.core:jackson-databind'
        optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
        optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
        optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-joda'
        optionalApi('com.fasterxml.jackson.module:jackson-module-kotlin') {
            exclude group: 'org.jetbrains.kotlin'
        }
        optionalApi "com.google.protobuf:protobuf-java:$protobufVersion"
        optionalApi "com.jayway.jsonpath:json-path:$jsonpathVersion"
        optionalApi "com.esotericsoftware:kryo:$kryoVersion"
        optionalApi 'io.micrometer:micrometer-core'
        optionalApi ('io.micrometer:micrometer-tracing') {
            exclude group: 'aopalliance'
        }
        optionalApi "io.github.resilience4j:resilience4j-ratelimiter:$resilience4jVersion"
        optionalApi "org.apache.avro:avro:$avroVersion"
        optionalApi 'org.jetbrains.kotlinx:kotlinx-coroutines-reactor'

        testImplementation "com.google.protobuf:protobuf-java-util:$protobufVersion"
        testImplementation "org.aspectj:aspectjweaver:$aspectjVersion"
        testImplementation 'io.micrometer:micrometer-observation-test'
        testImplementation ('io.micrometer:micrometer-tracing-integration-test') {
            exclude group: 'io.opentelemetry'
            exclude group: 'com.wavefront'
            exclude group: 'io.micrometer', module: 'micrometer-tracing-bridge-otel'
        }
    }

    dokkaHtmlPartial {
        outputDirectory.set(new File(buildDir, 'kdoc'))
        dokkaSourceSets {
            main {
                sourceRoots.setFrom(file('src/main/kotlin'))
                classpath.from(sourceSets['main'].runtimeClasspath)
                externalDocumentationLink {
                    url.set(new URL("https://docs.spring.io/spring-integration/docs/$version/api/"))
                    packageListUrl.set(file("$buildDir/docs/javadoc/element-list").toURI().toURL())
                }
                externalDocumentationLink {
                    url.set(new URL('https://projectreactor.io/docs/core/release/api/'))
                }
                externalDocumentationLink {
                    url.set(new URL('https://www.reactive-streams.org/reactive-streams-1.0.3-javadoc/'))
                }
            }
        }
    }
}

project('spring-integration-event') {
    description = 'Spring Integration ApplicationEvent Support'
    dependencies {
        api project(':spring-integration-core')
    }
}

project('spring-integration-feed') {
    description = 'Spring Integration RSS Feed Support'
    dependencies {
        api project(':spring-integration-core')
        api "com.rometools:rome:$romeToolsVersion"
    }
}

project('spring-integration-file') {
    description = 'Spring Integration File Support'
    dependencies {
        api project(':spring-integration-core')
        api "commons-io:commons-io:$commonsIoVersion"

        testImplementation project(':spring-integration-redis')
        testImplementation project(':spring-integration-redis').sourceSets.test.output
        testImplementation project(':spring-integration-jdbc')
        testImplementation "com.h2database:h2:$h2Version"
        testImplementation "io.lettuce:lettuce-core:$lettuceVersion"
        testImplementation "com.jayway.jsonpath:json-path:$jsonpathVersion"
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
    }
}

project('spring-integration-ftp') {
    description = 'Spring Integration FTP Support'
    dependencies {
        api project(':spring-integration-file')
        api "commons-net:commons-net:$commonsNetVersion"
        api 'org.springframework:spring-context-support'
        optionalApi "org.apache.ftpserver:ftpserver-core:$ftpServerVersion"

        testImplementation project(':spring-integration-file').sourceSets.test.output
    }
}

project('spring-integration-graphql') {
	description = 'Spring Integration GraphQL Support'
	dependencies {
		api project(':spring-integration-core')
		api "org.springframework.graphql:spring-graphql:$springGraphqlVersion"

        testImplementation 'org.springframework:spring-web'
	}
}

project('spring-integration-groovy') {
    description = 'Spring Integration Groovy Support'

    apply plugin: 'groovy'

    dependencies {
        api project(':spring-integration-scripting')
        api 'org.apache.groovy:groovy'
        api 'org.springframework:spring-context-support'

        testImplementation 'org.springframework:spring-web'

        testRuntimeOnly 'org.apache.groovy:groovy-dateutil'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
                '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    }
}

project('spring-integration-hazelcast') {
    description = 'Spring Integration Hazelcast Support'
    dependencies {
        api project(':spring-integration-core')
        api "com.hazelcast:hazelcast:$hazelcastVersion"

        testImplementation project(':spring-integration-jmx')
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-modules', 'java.se',
                '--add-exports', 'java.base/jdk.internal.ref=ALL-UNNAMED',
                '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
                '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
                '--add-opens', 'java.management/sun.management=ALL-UNNAMED',
                '--add-opens', 'jdk.management/com.sun.management.internal=ALL-UNNAMED',
                '-Dhazelcast.logging.type=log4j2'
    }
}

project('spring-integration-http') {
    description = 'Spring Integration HTTP Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-webmvc'
        providedImplementation "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"
        optionalApi "com.rometools:rome:$romeToolsVersion"
        optionalApi 'org.springframework:spring-webflux'

        testImplementation project(':spring-integration-security')
        testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
        testImplementation('org.springframework.security:spring-security-config') {
            exclude group: 'org.springframework'
        }
        testImplementation('org.springframework.security:spring-security-test') {
            exclude group: 'org.springframework'
        }
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'

        testRuntimeOnly "com.jayway.jsonpath:json-path:$jsonpathVersion"
    }
}

project('spring-integration-ip') {
    description = 'Spring Integration IP Support'
    dependencies {
        api project(':spring-integration-core')
        testImplementation project(':spring-integration-stream')
        testImplementation project(':spring-integration-event')

        testRuntimeOnly "com.esotericsoftware:kryo:$kryoVersion"
        testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.nio.channels.spi=ALL-UNNAMED',
                '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    }
}

project('spring-integration-jdbc') {
    description = 'Spring Integration JDBC Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-jdbc'
        optionalApi "org.postgresql:postgresql:$postgresVersion"

        testImplementation "com.h2database:h2:$h2Version"
        testImplementation "org.hsqldb:hsqldb:$hsqldbVersion"
        testImplementation "org.apache.derby:derby:$derbyVersion"
        testImplementation "org.apache.derby:derbytools:$derbyVersion"
        testImplementation "org.apache.derby:derbyclient:$derbyVersion"
        testImplementation "org.postgresql:postgresql:$postgresVersion"
        testImplementation "mysql:mysql-connector-java:$mysqlVersion"
        testImplementation "org.apache.commons:commons-dbcp2:$commonsDbcp2Version"
        testImplementation 'org.testcontainers:mysql'
        testImplementation 'org.testcontainers:postgresql'
        testImplementation 'org.testcontainers:oracle-xe'

        testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
        testRuntimeOnly "com.oracle.database.jdbc:ojdbc11:$oracleVersion"
    }
}

project('spring-integration-jms') {
    description = 'Spring Integration JMS Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-jms'
        providedImplementation "jakarta.jms:jakarta.jms-api:$jmsApiVersion"

        testImplementation("org.apache.activemq:artemis-server:$artemisVersion") {
            exclude group: 'org.jboss.logmanager'
        }
        testImplementation "org.apache.activemq:artemis-jakarta-client:$artemisVersion"
        testImplementation 'org.springframework:spring-oxm'
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
        testImplementation 'io.micrometer:micrometer-observation-test'
    }
}

project('spring-integration-jmx') {
    description = 'Spring Integration JMX Support'
    dependencies {
        api project(':spring-integration-core')

        testImplementation "org.aspectj:aspectjweaver:$aspectjVersion"
    }
}

project('spring-integration-jpa') {
    description = 'Spring Integration JPA Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-orm'
        optionalApi "jakarta.persistence:jakarta.persistence-api:$jpaApiVersion"

        testImplementation('org.springframework.data:spring-data-jpa') {
            exclude group: 'org.springframework'
        }
        testImplementation "com.h2database:h2:$h2Version"
        testImplementation "org.hibernate.orm:hibernate-core:$hibernateVersion"
    }
}

project('spring-integration-kafka') {
    description = 'Spring Integration for Apache Kafka'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.kafka:spring-kafka') {
            exclude group: 'org.springframework'
        }

        testImplementation 'org.springframework.kafka:spring-kafka-test'
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
    }
}

project('spring-integration-mail') {
    description = 'Spring Integration Mail Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-context-support'

        providedImplementation "org.eclipse.angus:jakarta.mail:$mailVersion"

        testImplementation ("com.icegreen:greenmail:$greenmailVersion") {
            exclude group: 'com.sun.mail'
            exclude group: 'jakarta.activation'
        }

        testRuntimeOnly 'org.apache.logging.log4j:log4j-jul'
    }
}

project('spring-integration-mongodb') {
    description = 'Spring Integration MongoDB Support'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.data:spring-data-mongodb') {
            exclude group: 'org.springframework'
        }
        optionalApi "org.mongodb:mongodb-driver-sync:$mongoDriverVersion"
        optionalApi "org.mongodb:mongodb-driver-reactivestreams:$mongoDriverVersion"

        testImplementation 'org.testcontainers:mongodb'
    }
}

project('spring-integration-r2dbc') {
    description = 'Spring Integration R2DBC Support'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.data:spring-data-r2dbc') {
            exclude group: 'org.springframework'
        }
        api 'org.springframework:spring-r2dbc'

        testImplementation "io.r2dbc:r2dbc-h2:$r2dbch2Version"
    }
}

project('spring-integration-mqtt') {
    description = 'Spring Integration MQTT Support'
    dependencies {
        api project(':spring-integration-core')
        api "org.eclipse.paho:org.eclipse.paho.client.mqttv3:$pahoMqttClientVersion"
        optionalApi "org.eclipse.paho:org.eclipse.paho.mqttv5.client:$pahoMqttClientVersion"

        testImplementation project(':spring-integration-jmx')
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
    }
}

project('spring-integration-redis') {
    description = 'Spring Integration Redis Support'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.data:spring-data-redis') {
            exclude group: 'org.springframework'
        }

        testImplementation "io.lettuce:lettuce-core:$lettuceVersion"
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    }
}

project('spring-integration-rsocket') {
    description = 'Spring Integration RSocket Support'
    dependencies {
        api project(':spring-integration-core')
        api "io.rsocket:rsocket-transport-netty:$rsocketVersion"
    }
}

project('spring-integration-scripting') {
    description = 'Spring Integration Scripting Support'
    dependencies {
        api project(':spring-integration-core')
        optionalApi ('org.jetbrains.kotlin:kotlin-script-util') {
            exclude group: 'org.jetbrains.kotlin', module: 'kotlin-daemon-client'
        }
        optionalApi 'org.jetbrains.kotlin:kotlin-compiler-embeddable'
        providedImplementation "org.graalvm.sdk:graal-sdk:$graalvmVersion"
        providedImplementation "org.graalvm.js:js:$graalvmVersion"

        testImplementation "org.jruby:jruby-complete:$jrubyVersion"
        testImplementation 'org.apache.groovy:groovy-jsr223'
        testImplementation "org.python:jython-standalone:$jythonVersion"

        testRuntimeOnly 'org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
                '--add-opens', 'java.base/java.io=ALL-UNNAMED',
                '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
                '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    }
}

project('spring-integration-security') {
    description = 'Spring Integration Security Support'
    dependencies {
        api project(':spring-integration-core')
        api('org.springframework.security:spring-security-messaging') {
            exclude group: 'org.springframework'
        }

        testImplementation('org.springframework.security:spring-security-config') {
            exclude group: 'org.springframework'
        }
    }
}

project('spring-integration-sftp') {
    description = 'Spring Integration SFTP Support'
    dependencies {
        api project(':spring-integration-file')
        api 'org.springframework:spring-context-support'
        api ("org.apache.sshd:sshd-sftp:$apacheSshdVersion") {
            exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
        }

        testImplementation project(':spring-integration-event')
        testImplementation project(':spring-integration-file').sourceSets.test.output
    }
}

project('spring-integration-smb') {
    description = 'Spring Integration SMB Support'
    dependencies {
        api project(':spring-integration-file')
        api "org.codelibs:jcifs:$jcifsVersion"

        testImplementation project(':spring-integration-file').sourceSets.test.output
    }
}

project('spring-integration-stomp') {
    description = 'Spring Integration STOMP Support'
    dependencies {
        api project(':spring-integration-core')
        optionalApi 'org.springframework:spring-websocket'

        testImplementation project(':spring-integration-websocket')
        testImplementation project(':spring-integration-websocket').sourceSets.test.output
        testImplementation project(':spring-integration-event')
        testImplementation("org.apache.activemq:artemis-stomp-protocol:$artemisVersion") {
            exclude group: 'org.jboss.logmanager'
        }
        testImplementation "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatVersion"
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'

        testRuntimeOnly 'org.springframework:spring-webmvc'
        testRuntimeOnly 'io.projectreactor.netty:reactor-netty-http'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.io=ALL-UNNAMED',
                '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
                '--add-opens', 'java.rmi/sun.rmi.transport=ALL-UNNAMED'
    }
}

project('spring-integration-stream') {
    description = 'Spring Integration Stream Support'
    dependencies {
        api project(':spring-integration-core')
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.io=ALL-UNNAMED'
    }
}

project('spring-integration-syslog') {
    description = 'Spring Integration Syslog Support'
    dependencies {
        api project(':spring-integration-ip')
    }
}

project('spring-integration-test') {
    description = 'Spring Integration Testing Framework'
    dependencies {
        api project(':spring-integration-core')
        api project(':spring-integration-test-support')
    }
}

project('spring-integration-webflux') {
    description = 'Spring Integration HTTP Support'
    dependencies {
        api(project(':spring-integration-http')) {
            exclude group: 'org.springframework', module: 'spring-webmvc'
        }
        api 'org.springframework:spring-webflux'
        optionalApi 'io.projectreactor.netty:reactor-netty-http'

        testImplementation "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"
        testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
        testImplementation 'org.springframework:spring-webmvc'
        testImplementation('org.springframework.security:spring-security-config') {
            exclude group: 'org.springframework'
        }
        testImplementation('org.springframework.security:spring-security-test') {
            exclude group: 'org.springframework'
        }
        testImplementation 'com.fasterxml.jackson.core:jackson-databind'
        testImplementation 'io.micrometer:micrometer-observation-test'
        testImplementation ('io.micrometer:micrometer-tracing-integration-test') {
            exclude group: 'io.opentelemetry'
            exclude group: 'com.wavefront'
            exclude group: 'io.micrometer', module: 'micrometer-tracing-bridge-otel'
        }

        testRuntimeOnly "com.jayway.jsonpath:json-path:$jsonpathVersion"
    }
}

project('spring-integration-websocket') {
    description = 'Spring Integration WebSockets Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-websocket'
        optionalApi 'org.springframework:spring-webmvc'
        providedImplementation "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"

        testImplementation project(':spring-integration-event')
        testImplementation "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatVersion"

        testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.base/java.io=ALL-UNNAMED',
                '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
                '--add-opens', 'java.rmi/sun.rmi.transport=ALL-UNNAMED'
    }
}

project('spring-integration-ws') {
    description = 'Spring Integration Web Services Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-oxm'
        api 'org.springframework:spring-webmvc'
        api('org.springframework.ws:spring-ws-core') {
            exclude group: 'org.springframework'
            exclude group: 'org.glassfish.jaxb'
        }

        providedImplementation "com.sun.xml.bind:jaxb-impl:$jaxbVersion"

        testImplementation "com.thoughtworks.xstream:xstream:$xstreamVersion"
        testImplementation('org.springframework.ws:spring-ws-support') {
            exclude group: 'org.springframework'
        }
        testImplementation 'org.springframework:spring-jms'
        testImplementation "jakarta.jms:jakarta.jms-api:$jmsApiVersion"
        testImplementation "org.igniterealtime.smack:smack-tcp:$smackVersion"
        testImplementation "org.igniterealtime.smack:smack-extensions:$smackVersion"
        testImplementation "org.eclipse.angus:angus-mail:$mailVersion"
    }
}

project('spring-integration-xml') {
    description = 'Spring Integration XML Support'
    dependencies {
        api project(':spring-integration-core')
        api 'org.springframework:spring-oxm'
        api('org.springframework.ws:spring-xml') {
            exclude group: 'org.springframework'
        }
        optionalApi('org.springframework.ws:spring-ws-core') {
            exclude group: 'org.springframework'
        }

        testImplementation "com.sun.xml.bind:jaxb-impl:$jaxbVersion"
        testImplementation "org.xmlunit:xmlunit-assertj3:$xmlUnitVersion"
    }

    tasks.withType(JavaForkOptions) {
        jvmArgs '--add-opens', 'java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED'
    }
}

project('spring-integration-xmpp') {
	description = 'Spring Integration XMPP Support'
	dependencies {
		api project(':spring-integration-core')
		api "org.igniterealtime.smack:smack-tcp:$smackVersion"
		api "org.igniterealtime.smack:smack-java8:$smackVersion"
		api "org.igniterealtime.smack:smack-extensions:$smackVersion"

        testImplementation project(':spring-integration-stream')
        testImplementation "org.igniterealtime.smack:smack-experimental:$smackVersion"
    }
}

project('spring-integration-zeromq') {
    description = 'Spring Integration ZeroMQ Support'
    dependencies {
        api project(':spring-integration-core')
        api "org.zeromq:jeromq:$jeroMqVersion"

        optionalApi 'com.fasterxml.jackson.core:jackson-databind'
    }
}

project('spring-integration-zip') {
    description = 'Spring Integration Zip Support'
    dependencies {
        api project(':spring-integration-file')
        api "org.zeroturnaround:zt-zip:$ztZipVersion"
    }
}


project('spring-integration-zookeeper') {
    description = 'Spring Integration Zookeeper Support'
    dependencies {
        api project(':spring-integration-core')
        api "org.apache.curator:curator-recipes:$curatorVersion"

        testImplementation "org.apache.curator:curator-test:$curatorVersion"
    }
}

project('spring-integration-bom') {
    description = 'Spring Integration (Bill of Materials)'

    apply plugin: 'java-platform'
    apply from: "${rootDir}/gradle/publish-maven.gradle"

    dependencies {
        constraints {
            javaProjects.sort { "$it.name" }.each {
                api it
            }
        }
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.javaPlatform
            }
        }
    }
}

task api(type: Javadoc) {
    group = 'Documentation'
    description = 'Generates aggregated Javadoc API documentation.'
    title = "${rootProject.description} ${version} API"
    options {
        encoding = 'UTF-8'
        memberLevel = JavadocMemberLevel.PROTECTED
        author = true
        header = rootProject.description
        use = true
        overview = 'src/api/overview.html'
        splitIndex = true
        links(project.ext.javadocLinks)
        addBooleanOption('Xdoclint:syntax', true) // only check syntax with doclint
    }

    source javaProjects.collect { project ->
        project.sourceSets.main.allJava
    }
    destinationDir = new File(buildDir, 'api')
    classpath = files(javaProjects.collect { project ->
        project.sourceSets.main.compileClasspath
    })
}

dokkaHtmlMultiModule {
    dependsOn api
    moduleName.set('spring-integration')
    outputDirectory.set(file("$buildDir/kdoc"))
}

apply from: "${rootDir}/gradle/docs.gradle"

task schemaZip(type: Zip) {
    group = 'Distribution'
    archiveClassifier = 'schema'
    description = "Builds -${archiveClassifier} archive containing all " +
            "XSDs for deployment at static.springframework.org/schema."

    duplicatesStrategy = DuplicatesStrategy.EXCLUDE

    javaProjects.each { subproject ->
        Properties schemas = new Properties()
        def shortName = subproject.name.replaceFirst("${rootProject.name}-", '')
        if (subproject.name.endsWith('-core')) {
            shortName = ''
        }

        subproject.sourceSets.main.resources.find {
            it.path.endsWith("META-INF${File.separator}spring.schemas")
        }?.withInputStream { schemas.load(it) }

        for (def key : schemas.keySet()) {
            File xsdFile = subproject.sourceSets.main.resources.find {
                it.path.replaceAll('\\\\', '/').endsWith(schemas.get(key))
            }
            assert xsdFile != null
            into("integration/$shortName") {
                from xsdFile.path
                rename { String fileName ->
                    String[] versionNumbers = project.version.split(/\./, 3)
                    fileName.replace('.xsd', "-${versionNumbers[0]}.${versionNumbers[1]}.xsd")
                }
            }
        }
    }
}

task docsZip(type: Zip, dependsOn: [reference, dokkaHtmlMultiModule]) {
    group = 'Distribution'
    archiveClassifier = 'docs'
    description = "Builds -${archiveClassifier} archive containing api and reference " +
            "for deployment at static.springframework.org/spring-integration/docs."

    from('src/dist') {
        include 'changelog.txt'
    }

    from(api) {
        into 'api'
    }

    from('build/docs/asciidoc') {
        into 'reference/html'
    }

    from('build/docs/asciidocPdf') {
        include 'index-single.pdf'
        rename 'index-single.pdf', 'spring-integration-reference.pdf'
        into 'reference/pdf'
    }

    from(dokkaHtmlMultiModule.outputDirectory) {
        into 'kdoc-api'
    }
}

task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
    group = 'Distribution'
    archiveClassifier = 'dist'
    description = "Builds -${archiveClassifier} archive, containing all jars and docs, " +
            "suitable for community download page."

    ext.baseDir = "${project.name}-${project.version}"

    from('src/dist') {
        include 'readme.txt'
        include 'notice.txt'
        into "${baseDir}"
        expand(copyright: new Date().format('yyyy'), version: project.version)
    }

    from("$project.rootDir") {
        include 'LICENSE.txt'
        into "${baseDir}"
    }

    from(zipTree(docsZip.archiveFile)) {
        into "${baseDir}/docs"
    }

    from(zipTree(schemaZip.archiveFile)) {
        into "${baseDir}/schema"
    }

    javaProjects.each { subproject ->
        into("${baseDir}/libs") {
            from subproject.jar
            from subproject.sourcesJar
            from subproject.javadocJar
        }
    }

    from(project(':spring-integration-bom').generatePomFileForMavenJavaPublication) {
        into "${baseDir}/libs"
        rename 'pom-default.xml', "spring-integration-bom-${project.version}.xml"
    }
}

task dist(dependsOn: assemble) {
    group = 'Distribution'
    description = 'Builds -dist, -docs and -schema distribution archives.'
}

apply from: "${rootDir}/gradle/publish-maven.gradle"

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact docsZip
            artifact schemaZip
            artifact distZip
        }
    }
}
