/*==========================================================================
Copyright since 2015, EPAM Systems

This file is part of Wilma.

Wilma is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Wilma is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Wilma.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================*/

ext.componentDescription = "Wilma-Service-API"

apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'java-library'
apply plugin: 'jacoco'

def isSnapshot = project.version.contains('SNAPSHOT')

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation group: 'org.slf4j', name: 'slf4j-api', version: "${orgSfl4jVersion}"
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}"
    implementation group: 'commons-httpclient', name: 'commons-httpclient', version:'3.1'
//    implementation group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '5.2.1'
    implementation group: 'commons-io', name: 'commons-io', version:'2.11.0'
    implementation group: 'commons-validator', name: 'commons-validator', version:'1.7'
    implementation group: 'com.github.everit-org.json-schema', name: 'org.everit.json.schema', version: '1.14.1'
    implementation "$googleGuavaApi"
    implementation "$orgJsonApi"
    testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockitoCoreVersion}"
    testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoCoreVersion}"
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jUnitVersion}"
    testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jUnitVersion}"
}

test.useJUnitPlatform()

jacoco {
    toolVersion = "0.8.11"
}
jacocoTestReport {
    reports {
        xml.required
    }
}
test.finalizedBy jacocoTestReport

task docs(type: Javadoc) {
    destinationDir = file("$buildDir/docs/all")
    options.memberLevel = JavadocMemberLevel.PRIVATE
    source += files(sourceSets.main.java)
    classpath += files(sourceSets.main.compileClasspath)
}

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

java {
    withJavadocJar()
    withSourcesJar()
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId = archivesBaseName
            from components.java
            pom {
                name = 'Wilma-Service-API'
                description = 'Java Service API to work with Wilma tool via its public interfaces. This API can be built into other apps those need to communicate with Wilma.'
                url = 'https://github.com/epam/Wilma/wiki'
                scm {
                    connection = 'https://github.com/epam/Wilma.git'
                    developerConnection = 'https://github.com/epam/Wilma'
                    url = 'https://github.com/epam/Wilma/tree/master/'
                }
                licenses {
                    license {
                        name = 'GPL-v3.0'
                        url = 'http://www.gnu.org/licenses/gpl-3.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'tkohegyi'
                        name = 'Tamas Kohegyi'
                        email = 'tamas_kohegyi@epam.com'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            def stagingRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
            def snapshotRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
            url isSnapshot ? snapshotRepoUrl : stagingRepoUrl
            credentials {
                username = rootProject.findProperty('ossrhUsername') ?: ''
                password = rootProject.findProperty('ossrhPassword') ?: ''
            }
        }
    }
}

signing {
    required { isSnapshot }
    sign publishing.publications.mavenJava
}
