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

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

configurations {
    // Required to keep Gradle classes off the test compile classpath.
    gradleConf.extendsFrom compileClasspath
}

ext {
    pomDescription = 'Support for Grails documentation generation in Gradle builds.'
    sbomProjectType = org.cyclonedx.model.Component.Type.LIBRARY.name()
}

dependencies {
    implementation platform(project(':grails-gradle-bom'))

    gradleConf gradleApi()

    // grails-docs classes are used in Gradle builds,
    // so we must compile with Groovy 3 until Gradle upgrades to Groovy 4.
    compileOnly 'org.codehaus.groovy:groovy'
    compileOnly 'org.codehaus.groovy:groovy-ant'

    api 'org.apache.commons:commons-text'
    api 'org.slf4j:jcl-over-slf4j'
    api 'org.apache.ant:ant'
    api 'org.grails:grails-gdoc-engine'
    api 'org.yaml:snakeyaml'

    api 'org.asciidoctor:asciidoctorj'
    implementation 'org.springframework.boot:spring-boot-gradle-plugin'

    runtimeOnly 'org.slf4j:slf4j-api'
    testImplementation('org.spockframework:spock-core') {
        transitive = false
    }

    testImplementation 'org.codehaus.groovy:groovy-test-junit5'
    testImplementation 'org.junit.jupiter:junit-jupiter-api'
    testImplementation 'org.junit.platform:junit-platform-runner'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

sourceSets {
    main {
        compileClasspath = configurations.gradleConf
    }
}

tasks.register('docFilesJar', Jar).configure {Jar it ->
    it.description = 'Package up files used for generating documentation.'
    it.archiveVersion = null
    it.archiveFileName = 'grails-doc-files.jar'
    it.from 'src/main/template'
}

tasks.named('jar', Jar).configure { Jar it ->
    it.from docFilesJar
}

jar.dependsOn docFilesJar

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