
plugins {
    id 'org.sonarqube' version '2.7'
    id 'java'
    id 'eclipse'
    id 'maven'
    id 'signing'
    id 'jacoco'
}

group = 'ch.obermuhlner'
version = '2.3.2'
archivesBaseName = 'big-math'

ext {
    moduleName = "ch.obermuhlner.math.big"

    if (!project.hasProperty("ossrhUsername")) {
        ossrhUsername = "undefined"
    }
    if (!project.hasProperty("ossrhPassword")) {
        ossrhPassword="undefined"
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

compileJava   {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}

dependencies {
    testCompile 'junit:junit:4.12'
}

test {
    testLogging {
        events "failed"
        exceptionFormat "full"
    }
}

sonarqube {
    properties {
        property "sonar.projectKey", "big-math"
    }
}

jacocoTestReport {
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

check.dependsOn jacocoTestReport

jar {
    manifest {
        attributes(
                "Automatic-Module-Name": moduleName,
                "Bundle-ManifestVersion": 2,
                "Bundle-Name": archivesBaseName,
                "Bundle-SymbolicName": moduleName,
                "Bundle-Version": version,
                "Export-Package": "ch.obermuhlner.math.big, ch.obermuhlner.math.big.stream")
    }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    //archives jar // no longer needed tp add - will lead to duplicate
    archives sourcesJar
    archives javadocJar
}

signing {
    required {
        gradle.taskGraph.hasTask("uploadArchives")
    }

    sign configurations.archives
}

uploadArchives {
	repositories {
	    mavenDeployer {
	        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
	
	        repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
	            authentication(userName: ossrhUsername, password: ossrhPassword)
	        }
	
	        snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
	            authentication(userName: ossrhUsername, password: ossrhPassword)
	        }
	
	        pom.project {
	            name 'Big Math'
	            packaging 'jar'
	            // optionally artifactId can be defined here 
	            description 'Math functions for BigDecimal.'
	            url 'https://github.com/eobermuhlner/big-math'
	
	            scm {
	                connection 'scm:git:git://github.com/big-math.git'
	                developerConnection 'scm:ssh://github.com:eobermuhlner/big-math.git'
	                url 'https://github.com/eobermuhlner/big-math/'
	            }
	
	            licenses {
	                license {
	                    name 'MIT License'
	                    url 'https://raw.githubusercontent.com/eobermuhlner/big-math/master/LICENSE.txt'
	                }
	            }
	
	            developers {
	                developer {
	                    id 'eobermuhlner'
	                    name 'Eric Obermuhlner'
	                    email 'eobermuhlner@gmail.com'
	                }
	            }
	        }
	    }
	}
}

// See http://central.sonatype.org/pages/gradle.html
