plugins {
    id 'java-library'
    id 'signing'
    id 'maven'
}

group = 'io.appium'
version = '2.0.2'
archivesBaseName = 'mitmproxy-java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.java-websocket:Java-WebSocket:1.4.0'
    implementation group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0-m02'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.8'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
    implementation group: 'org.zeroturnaround', name: 'zt-exec', version: '1.10'
    implementation group: 'org.zeroturnaround', name: 'zt-process-killer', version: '1.9'
    implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.26'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
    testCompile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
    testCompile group: 'org.assertj', name: 'assertj-core', version: '3.12.2'

    compileOnly 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'org.projectlombok:lombok:1.18.8'

    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.0'
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}
task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}
artifacts {
    archives javadocJar, sourcesJar
}
signing {
    setRequired {
        // condition for when signing is required
        gradle.taskGraph.hasTask("uploadArchives")
    }
    sign configurations.archives
}


// Build, sign, and upload
uploadArchives {
    repositories {
        mavenDeployer {

            // Sign POM
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            // Destination
            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: 'username', password: 'password')
            }
            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: 'username', password: 'password')
            }

            // Add required metadata to POM
            pom.project {
                name 'mitmproxy-java'
                packaging 'jar'
                description 'A bridge between Python\'s mitmproxy and Java programs. Built on top of mitmproxy-node'
                url 'https://github.com/appium/mitmproxy-java'

                scm {
                    connection 'scm:git:git://github.com/appium/mitmproxy-java.git'
                    developerConnection 'scm:git:ssh://github.com/appium/mitmproxy-java.git'
                    url 'http://github.com/appium/mitmproxy-java/tree/master'
                }

                licenses {
                    license {
                        name 'The Apache License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                developers {
                    developer {
                        id 'jonahss'
                        name 'Jonah Stiennon'
                        email 'jonah@cloudgrey.io'
                        organization 'Cloud Grey'
                        organizationUrl 'https://cloudgrey.io'
                    }
                }
            }
        }
    }
}
