buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        maven {
            url "https://snapshots.repositories.eventuate.io/repository"
        }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
        classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:$springCloudContractDependenciesVersion"
        classpath "io.eventuate.tram.testingsupport.springcloudcontract:eventuate-tram-spring-testing-support-cloud-contract-plugins-gradle:$eventuateTramSpringTestingSupportCloudContractVersion"
    }
}


apply plugin: "io.eventuate.tram.spring.testing.cloudcontract.plugins.gradle.ConfigureContractRepoDirPlugin"

allprojects {
    group = "io.eventuate.examples.tram.sagas.customersandorders"
}

subprojects {

    apply plugin: "java-library"

    java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(17)
        }
    }

    repositories {
        mavenCentral()
        eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
    }

    dependencies {
        implementation(platform("io.eventuate.platform:eventuate-platform-dependencies:$eventuatePlatformVersion"))

        implementation(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"))

        implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"))

//        dependencyManagement {
//            imports {
//                mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
//            }
//        }

//        implementation(platform("org.springframework.cloud:spring-cloud-contract-dependencies:$springCloudContractDependenciesVersion"))

        constraints {
            implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:$springdocVersion"
        }

        testImplementation "org.springframework.boot:spring-boot-starter-test"

    }

    tasks.withType(Copy).all { duplicatesStrategy 'WARN' }

    tasks.withType(JavaCompile) {
        options.compilerArgs << "-parameters"
    }

    tasks.withType(Test).configureEach {
         useJUnitPlatform()
    }

    if (System.getenv("GRADLE_CACHE_CHANGING_VERSIONS_IN_MINUTES") != null)
        configurations.all {
            resolutionStrategy.cacheChangingModulesFor Integer.parseInt(System.getenv("GRADLE_CACHE_CHANGING_VERSIONS_IN_MINUTES")), 'minutes'
        }

}


task clean(type:Delete) {
    delete 'build/repos'
}


task endToEndTests(type: GradleBuild) {
    tasks = [":end-to-end-tests:endToEndTest"]
    dependsOn(":end-to-end-tests:clean")
}


task compileAll(type: GradleBuild) {
    tasks = ["endToEndTestClasses", "componentTestClasses", "integrationTestClasses", "testClasses", "assemble"]
}

task testEachService(type: GradleBuild) {
    tasks = ["test", "integrationTest", "contractTest", "componentTest"]
}

