buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
        classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0'
    }
}

ext {
    libs = [
            jsonSmart: 'net.minidev:json-smart:2.5.0',
            slf4jApi: 'org.slf4j:slf4j-api:2.0.11',
            gson: 'com.google.code.gson:gson:2.10.1',
            hamcrest: 'org.hamcrest:hamcrest:2.2',
            jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.16.1',
            jettison: 'org.codehaus.jettison:jettison:1.5.4',
            jsonOrg: 'org.json:json:20231013',
            tapestryJson: 'org.apache.tapestry:tapestry-json:5.8.3',
            jakartaJsonP: 'jakarta.json:jakarta.json-api:2.0.2',
            jakartaJsonB: 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',

            test: [
                    'commons-io:commons-io:2.15.0',
                    'junit:junit:4.13.+',
                    'org.junit.vintage:junit-vintage-engine:5.10.+',
                    'org.assertj:assertj-core:3.25.1',
                    'org.hamcrest:hamcrest:2.2',
                    'org.glassfish:jakarta.json:2.0.1',
                    'org.eclipse:yasson:2.0.4',
                    //'org.apache.johnzon:johnzon-jsonb:1.2.21',
                    'org.slf4j:slf4j-simple:2.0.9',
                    'com.google.code.gson:gson:2.10.1',
                    'org.hamcrest:hamcrest:2.2',
                    'com.fasterxml.jackson.core:jackson-databind:2.16.1',
                    'org.codehaus.jettison:jettison:1.5.4',
                    'org.json:json:20231013',
                    'org.apache.tapestry:tapestry-json:5.8.3',
                    'jakarta.json:jakarta.json-api:2.0.2',
                    'jakarta.json.bind:jakarta.json.bind-api:2.0.0'

            ]
    ]
    snapshotVersion = true
}

allprojects {
    ext.displayName = null
    ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss')

    group = 'com.jayway.jsonpath'
    version = '2.9.0' + (snapshotVersion ? "-SNAPSHOT" : "")

}

subprojects {
    apply plugin: 'java'
    apply plugin: 'java-library'
    apply plugin: 'maven-publish'
    apply plugin: 'signing'
    apply plugin: 'biz.aQute.bnd.builder'

    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    repositories {
        mavenCentral()
    }

    java {
        withJavadocJar()
        withSourcesJar()
    }

    test {
        useJUnitPlatform()

        systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")

        testLogging {
            events "passed", "skipped", "failed"
        }
    }

    signing {
        sign publishing.publications
        required { !snapshotVersion && gradle.taskGraph.hasTask("publish") }
    }

    javadoc {
        if (JavaVersion.current().isJava8Compatible()) {
            options.addStringOption('Xdoclint:none', '-quiet')
        }

        if(JavaVersion.current().isJava9Compatible()) {
            options.addBooleanOption('html5', true)
        }
    }

    publishing {
        repositories {
            maven {
                def releaseRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                def snapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
                url = snapshotVersion ? snapshotRepo : releaseRepo
                credentials {
                    username = project.hasProperty('sonatypeOssUsername') ? sonatypeOssUsername : "Unknown user"
                    password = project.hasProperty('sonatypeOssPassword') ? sonatypeOssPassword : "Unknown password"
                }
            }
        }
        publications {
            mavenJava(MavenPublication) {
                from components.java

                artifactId = jar.baseName

                pom {
                    name = jar.baseName
                    description = 'A library to query and verify JSON'
                    url = 'https://github.com/jayway/JsonPath'

                    licenses {
                        license {
                            name = "The Apache Software License, Version 2.0"
                            url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
                            distribution = "repo"
                        }
                    }

                    scm {
                        url = 'scm:git:git://github.com/jayway/JsonPath.git'
                        connection = 'scm:git:git://github.com/jayway/JsonPath.git'
                        developerConnection = 'scm:git:git://github.com/jayway/JsonPath.git'
                    }

                    developers {
                        developer {
                            id = 'kalle.stenflo'
                            name = 'Kalle Stenflo'
                            email = 'kalle.stenflo (a) gmail.com'
                        }
                    }
                }
            }
        }
    }
}

wrapper {
    gradleVersion = '7.4.2'
}

//Task used by Heroku for staging
task stage(dependsOn: [':json-path-web-test:clean', 'json-path-web-test:jar', 'json-path-web-test:shadowJar']) {}

