/* groovylint-disable DuplicateStringLiteral, NestedBlockDepth, NoDef, VariableTypeRequired */
/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Groovy project to get you started.
 * For more details take a look at the Groovy Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.5/userguide/tutorial_groovy_projects.html
 */

plugins {
    id 'maven-publish'
    // Apply the groovy plugin to add support for Groovy
    id 'groovy'

    // Apply the java-library plugin for API and implementation separation.
    id 'java-library'

    // Needed for signing artifacts pushed to https://oss.sonatype.org/
    id 'signing'

    id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}

version = project.findProperty('CICD_TAG') ?: '0.0.0-DEV'

group = 'io.github.dontshavetheyak'

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    withSourcesJar()
}

task removeDuplicateFiles(type: Delete) {
    delete "${buildDir}/tmp/groovydoc"
}

groovydoc {
    use = true
    overviewText = resources.text.fromString('Bringing the Zen of Python to Jenkins.')
    link('https://docs.oracle.com/javase/8/docs/api/', 'java.')
    link('https://javadoc.jenkins.io', 'hudson.,jenkins.')
}

task groovydocJar(type: Jar, dependsOn: groovydoc ) {
    classifier 'javadoc' // must use javadoc classifier to be able to deploy to Sonatype
    from groovydoc.destinationDir
}

groovydoc.finalizedBy removeDuplicateFiles

publishing {
    publications {
        mavenJava(MavenPublication) {
            from(components.java)

            artifact(groovydocJar) {
                classifier = 'javadoc'
            }

            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }

            pom {
                name = 'jenkins-std-lib'
                description = 'A Jenkins shared library for commonly used CI/CD functions.'
                url = 'https://github.com/DontShaveTheYak/jenkins-std-lib'
                inceptionYear = '2020'

                licenses {
                    license {
                        name = 'GNU General Public License v3.0'
                        url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'shadycuz'
                        name = 'Levi Blaney'
                        email = 'shadycuz@gmail.com'
                    }
                }
                scm {
                    url = 'https://github.com/DontShaveTheYak/jenkins-std-lib'
                    connection = 'scm:https://github.com/DontShaveTheYak/jenkins-std-lib.git'
                    developerConnection = 'scm:git@github.com:DontShaveTheYak/jenkins-std-lib.git'
                }
            }
        }
    }
}

nexusPublishing {
    repositories {
        sonatype()
    }
}

signing {
    def signingKey = findProperty('signingKey')
    def signingPassword = findProperty('signingPassword')

    useInMemoryPgpKeys(signingKey, signingPassword)

    sign publishing.publications.mavenJava
}

sourceSets {
    main {
        groovy {
            srcDirs = ['src']
        }
    }
}

repositories {
    // Gradle emits a warning because jcenter() method is going to be
    // removed in Grafle 8.0 but google() or mavenCentral() can not find
    // org.connectbot.jbcrypt:jbcrypt:1.0.0.
    jcenter()
    mavenCentral()
    maven {
        url 'https://repo.jenkins-ci.org/releases/'
    }
}

configurations {
    contrib.extendsFrom compileOnly
}

dependencies {
    // Use the latest Groovy version for building this library
    compileOnly('org.codehaus.groovy:groovy-all:3.0.14')
    compileOnly('org.jenkins-ci.main:jenkins-core:2.383')
    compileOnly('com.cloudbees:groovy-cps:1.34')
}

wrapper {
    gradleVersion = '7.5.1'
    distributionType = Wrapper.DistributionType.ALL
}

task downloadJars(type: Copy) {

    into "${buildDir}/dependencies"

    from configurations.contrib

}
