/*
 *  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 'groovy'
    id 'java-library'
    id 'org.apache.grails.buildsrc.publish'
    id 'org.apache.grails.buildsrc.sbom'
}

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

ext {
    pomTitle = 'Grails GORM'
    pomDescription = 'GORM - Grails Data Access Framework'
    pomDevelopers = [
            'graemerocher': 'Graeme Rocher',
            'jeffscottbrown': 'Jeff Brown',
            'burtbeckwith': 'Burt Beckwith',
            'jameskleeh': 'James Kleeh',
            'puneetbehl': 'Puneet Behl',
            'jamesfredley': 'James Fredley'
    ]
}

dependencies {

    implementation platform(project(':grails-bom'))

    api project(':grails-datastore-core'), {
        // api: BuildableCriteria, ConnectionSourcesProvider, Criteria, Datastore, MappingContext, PersistentEntity,
        //      ProjectionList, Query, QueryableCriteria, QueryCreator, Session, SessionCallback, ValidatorRegistry,
        //      VoidSessionCallback
        // impl: Association, AssociationQuery, Basic, ClassUtils, Connection, ConnectionSource, DatastoreUtils,
        //       NameUtils, PersistentProperty, Restrictions, QueryArgumentsAware
        if (excludeUnusedTransDeps) {
            // API dependencies in grails-datastore-core
            exclude group: 'jakarta.persistence', module: 'jakarta.persistence-api'
            //exclude group: 'org.javassist', module: 'javassist' // activate JavassistProxyFactory
            exclude group: 'org.springframework', module: 'spring-context'
            exclude group: 'org.springframework', module: 'spring-core'
            exclude group: 'org.springframework', module: 'spring-tx'
        }
    }
    api project(':grails-datamapping-validation'), {
        // api: BeforeValidateHelper, CascadingValidator, DefaultValidatorRegistry
        if (excludeUnusedTransDeps) {
            // API dependencies in grails-datamapping-validation
            exclude group: 'commons-validator', module: 'commons-validator'
            exclude group: 'org.apache.grails.data', module: 'grails-datastore-core'
            exclude group: 'org.springframework', module: 'spring-context'
        }
    }
    api 'jakarta.annotation:jakarta.annotation-api', {
        // api: PostConstruct, PreDestroy
    }
    api 'jakarta.persistence:jakarta.persistence-api', {
        // api: FetchType, JoinType
    }
    api 'org.springframework:spring-context', {
        // api: Validator
    }
    api 'org.springframework:spring-jdbc', {
        // api: DriverManagerDataSource
        // impl: DelegatingDataSource, TransactionAwareDataSourceProxy
    }
    api 'org.springframework:spring-tx', {
        // api: Isolation, PlatformTransactionManager, Propagation, TransactionAttribute, TransactionDefinition,
        //      TransactionException
        // impl: DataIntegrityViolationException, DefaultTransactionDefinition, LazyConnectionDataSourceProxy,
        //       NoRollbackRuleAttribute, RollbackRuleAttribute, TransactionCallback, TransactionDefinition,
        //       TransactionStatus, TransactionSynchronizationManager, TransactionSystemException
    }

    implementation 'org.apache.groovy:groovy', {
        // impl: Closure, ClosureExpression, DelegatesTo, GroovyASTTransformationClass
        // comp: CompileDynamic, CompileStatic
    }
    implementation 'org.hibernate.validator:hibernate-validator', {
        // impl: ResourceBundleMessageInterpolator
    }

    compileOnlyApi "jakarta.el:jakarta.el-api:$elApiVersion"

    runtimeOnly "org.glassfish.expressly:expressly:$defaultElImplementationVersion", {
        // Note: Default EL implementation included for convenience,
        //       can be replaced by downstream consumers
    }

    compileOnly 'org.slf4j:slf4j-api'

    testImplementation project(':grails-core'), {
        // impl: ValidationException
    }
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testImplementation 'org.spockframework:spock-core'

    testRuntimeOnly 'com.h2database:h2'
    testRuntimeOnly 'org.slf4j:slf4j-nop' // Get rid of warning about missing slf4j implementation during tests
}

//compileGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005']

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/test-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
}
