/*
 *  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 'project-report'
    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 {
    // TODO: RestfulReverseUrlRenderingTests seems to fail under the CI Build when using parallel
    configuredTestParallel = isCiBuild ? 1 : rootProject.findProperty('configuredTestParallel')
    testForkEvery = isCiBuild ? 10 : 20
    testJvmArgs = ['-Xmx1536M']

    pomTitle = 'Groovy Server Pages (GSP)'
    pomDescription = 'Groovy Server Pages (GSP) - A server-side view rendering technology based on Groovy'
    pomDevelopers = ['graemerocher': 'Graeme Rocher']
}

dependencies {

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

    api project(':grails-gsp-core'), { // GroovyPageResourceLoader, GroovyPagesTemplateEngine, CachingGroovyPageStaticResourceLocator
        // API dependencies in grails-gsp
        exclude group: 'org.apache.grails.bootstrap', module: 'grails-bootstrap'
        //exclude group: 'org.apache.groovy', module: 'groovy-templates' // TemplateEngine
    }
    api project(':grails-web-gsp'), { // PageRenderer
        // API dependencies in grails-web-gsp
        exclude group: 'org.apache.grails.views', module: 'grails-gsp-core'
        exclude group: 'org.apache.grails.views', module: 'grails-web-taglib'
        exclude group: 'org.apache.grails.web', module: 'grails-web-common'
    }
    api project(':grails-web-taglib'), { // TagLibraryInvoker, TagLib, TagLibrary
        // API dependencies in grails-web-taglib
        exclude group: 'org.apache.grails.views', module: 'grails-taglib'
        exclude group: 'org.apache.grails.views', module: 'grails-web-common'
    }
    api project(':grails-encoder'), { // CodecLookup, Encoder
        // API dependencies in grails-encoder
        exclude group: 'org.apache.groovy', module: 'groovy'
        exclude group: 'org.apache.groovy', module: 'groovy-json'
        exclude group: 'org.apache.grails', module: 'grails-core'
        exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
        exclude group: 'org.slf4j', module: 'slf4j-api'
        exclude group: 'org.springframework', module: 'spring-web'
    }
    api project(':grails-web-url-mappings'), { // LinkGenerator
        // API dependencies in grails-web-url-mappings
        exclude group: 'org.apache.grails.web', module: 'grails-web-common'
        //exclude group: 'org.apache.grails.data', module: 'grails-datamapping-validation '// Constrained
    }
    api 'org.springframework:spring-context' // MessageSource, Errors, MessageSourceResolvable, DefaultMessageSourceResolvable, NoSuchMessageException
    api 'org.springframework.boot:spring-boot' // ServletRegistrationBean

    implementation project(':grails-taglib'), { // GroovyPageAttributes
        // API dependencies in grails-taglib
        exclude group: 'org.apache.grails', module: 'grails-core'
        exclude group: 'org.apache.grails', module: 'grails-encoder'
        exclude group: 'org.springframework', module: 'spring-core'
    }

    implementation project(':grails-web-gsp-taglib'), { // RenderTagLib
        // API dependencies in grails-web-gsp-taglib
        exclude group: 'org.apache.grails.views', module: 'grails-taglib'
        exclude group: 'org.apache.grails.views', module: 'grails-web-gsp'
    }
    implementation 'org.apache.commons:commons-text' // StringEscapeUtils
    implementation 'org.apache.groovy:groovy-xml' // MarkupBuilder
    implementation project(':grails-core'), { // Config
        // API dependencies in grails-core
        exclude group: 'org.apache.groovy', module: 'groovy'
        exclude group: 'jakarta.inject', module: 'jakarta.inject-api'
        exclude group: 'jakarta.persistence', module: 'jakarta.persistence-api'
        exclude group: 'jakarta.annotation', module: 'jakarta.annotation-api'
        exclude group: 'org.apache.grails.bootstrap', module: 'grails-bootstrap'
        exclude group: 'org.apache.grails.data', module: 'grails-datastore-core'
        exclude group: 'org.apache.grails', module: 'grails-spring'
        exclude group: 'org.slf4j', module: 'jcl-over-slf4j'
        exclude group: 'org.slf4j', module: 'slf4j-api'
        exclude group: 'org.yaml', module: 'snakeyaml'
        exclude group: 'org.springframework', module: 'spring-beans'
        exclude group: 'org.springframework', module: 'spring-core'
        exclude group: 'org.springframework', module: 'spring-context'
        exclude group: 'org.springframework', module: 'spring-tx'
        exclude group: 'org.springframework.boot', module: 'spring-boot'
        exclude group: 'org.springframework.boot', module: 'spring-boot-autoconfigure'
    }
    implementation project(':grails-spring'), { // RuntimeSpringConfiguration
        // API dependencies in grails-spring
        exclude group: 'org.springframework', module: 'spring-tx'
        exclude group: 'org.springframework', module: 'spring-web'
        exclude group: 'org.springframework', module: 'spring-context'
        exclude group: 'org.apache.grails.bootstrap', module: 'grails-bootstrap'
        exclude group: 'org.apache.groovy', module: 'groovy-xml'
    }
    implementation project(':grails-web-common'), {
        // API dependencies in grails-web-common
        exclude group: 'org.apache.groovy', module: 'groovy-templates'
        exclude group: 'org.apache.grails', module: 'grails-core'
        exclude group: 'org.apache.grails', module: 'grails-databinding'
        exclude group: 'org.apache.grails', module: 'grails-encoder'
        exclude group: 'org.springframework', module: 'spring-webmvc'
        exclude group: 'org.springframework', module: 'spring-context-support'
    }
    implementation project(':grails-web-mvc'), { // SynchronizerTokensHolder
        // API dependencies in grails-web-mvc
        exclude group: 'org.apache.grails.web', module: 'grails-web-common'
        exclude group: 'org.apache.grails.web', module: 'grails-web-url-mappings'
    }
    implementation 'org.springframework:spring-beans' // PropertyEditorRegistry

    astImplementation project(':grails-web-core'), {
        // API dependencies in grails-web
        exclude group: 'org.apache.grails.web', module: 'grails-web-common'
        exclude group: 'org.apache.grails.web', module: 'grails-web-databinding'
        exclude group: 'org.apache.grails.web', module: 'grails-web-mvc'
        exclude group: 'org.apache.grails.web', module: 'grails-web-url-mappings'
        exclude group: 'org.apache.grails.views', module: 'grails-web-gsp'
    }
    astImplementation project(':grails-controllers'), {
        // API dependencies in grails-plugin-controllers
        //exclude group: 'org.apache.grails', module: 'grails-core' // TraitInjector
        exclude group: 'org.apache.grails.web', module: 'grails-web-core'
        exclude group: 'org.apache.grails', module: 'grails-mimetypes'
        exclude group: 'org.apache.grails', module: 'grails-validation'
        exclude group: 'org.apache.grails', module: 'grails-domain-class'
        exclude group: 'org.springframework.boot', module: 'spring-boot-autoconfigure'
    }

    runtimeOnly project(':grails-web-jsp'), { // Provided by Application for JSP support
        // API dependencies in grails-web-jsp
        exclude group: 'org.apache.grails.views', module: 'grails-web-gsp'
    }

    api project(':grails-codecs') // Registers CodecLookup bean

    testCompileOnly 'jakarta.annotation:jakarta.annotation-api'

    testImplementation project(':grails-web-jsp'), { // TagLibraryResolverImpl
        // API dependencies in grails-web-jsp
        exclude group: 'org.apache.grails.views', module: 'grails-web-gsp'
    }
    testImplementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api'
    testImplementation "jakarta.servlet.jsp:jakarta.servlet.jsp-api:$jspApiVersion"
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testImplementation 'org.springframework:spring-test'
    testImplementation 'org.spockframework:spock-core'
    testImplementation 'org.apache.grails:grails-testing-support-datamapping'
    testImplementation project(':grails-testing-support-core')
    testImplementation project(':grails-testing-support-web')

    testRuntimeOnly 'org.glassfish.web:jakarta.servlet.jsp.jstl'
    testRuntimeOnly project(':grails-url-mappings')
    testRuntimeOnly project(':grails-async')
}

apply {
    // java-configuration must be applied first since tasks are now lazy registered
    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/docs-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')
    from rootProject.layout.projectDirectory.file('gradle/grails-extension-gradle-config.gradle')
}
