/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

plugins {
    id 'java-library'
    id 'org.apache.grails.gradle.grails-plugin'
    id 'org.apache.grails.buildsrc.publish'
    id 'org.apache.grails.buildsrc.sbom'
}

version = projectVersion
group = 'org.apache.grails'

ext {
    gormApiDocs = true
    pomTitle = 'Grails Database Migration Plugin'
    pomDescription = 'The Database Migration plugin helps you manage database changes, via Liquibase, while developing Grails applications'
    pomDevelopers = [
            'kazukiyamamoto': 'Kazuki YAMAMOTO',
            'jamesfredley'  : 'James Fredley',
    ]
}

dependencies {
    // TODO: Clarify and clean up dependencies
    implementation platform(project(':grails-bom')) {
        exclude group: 'org.liquibase', module: 'liquibase-core'
    }

    implementation("org.liquibase:liquibase-core:$liquibaseHibernate5Version")
    implementation("org.liquibase.ext:liquibase-hibernate5:$liquibaseHibernate5Version") {
        exclude group: 'org.hibernate', module: 'hibernate-core'
        exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
        exclude group: 'org.hibernate', module: 'hibernate-envers'
        exclude group: 'com.h2database', module: 'h2'
        exclude group: 'org.liquibase', module: 'liquibase-commercial'
    }

    implementation(project(':grails-shell-cli')) {
        exclude group: 'org.slf4j', module: 'slf4j-simple'

        // TODO: the shell cli is exporting groovy 3, while this project is expected to use groovy 4
        //       this plugin needs split into commands & the plugin itself so that different versions
        //       of groovy can be used
        exclude group: 'org.codehaus.groovy'
    }

    compileOnly 'org.springframework.boot:spring-boot-starter-logging'
    compileOnly 'org.springframework.boot:spring-boot-autoconfigure'
    compileOnly project(':grails-data-hibernate5')
    compileOnly project(':grails-core')
    compileOnly 'org.apache.groovy:groovy-sql'
    compileOnly 'org.apache.groovy:groovy-xml'

    testImplementation 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation project(':grails-data-hibernate5')
    testImplementation project(':grails-core')
    testImplementation project(':grails-testing-support-datamapping')
    testImplementation project(':grails-testing-support-web')
    testImplementation 'com.h2database:h2'

    constraints {
        implementation("org.liquibase:liquibase-core") {
            version {
                strictly "$liquibaseHibernate5Version"
            }
        }
        implementation("org.liquibase.ext:liquibase-hibernate5") {
            version {
                strictly "$liquibaseHibernate5Version"
            }
        }
    }
}

tasks.named('jar', Jar) {
    exclude('testapp/**/**')
}

tasks.withType(Test).configureEach {
    develocity.testRetry {
        if (isCiBuild) {
            maxRetries = 2
            maxFailures = 20
            failOnPassedAfterRetry = true
            filter {
                excludeClasses.add('*.GroovyChangeLogSpec')
            }
        }
    }
}

apply {
    from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/hibernate5-test-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/grails-extension-gradle-config.gradle')
}
