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

group = 'com.amdelamar'
version = '2.2.0'
description = 'Password hashing utility in Java. Supports PBKDF2 hmac SHA1/SHA256/SHA512, BCRYPT, and SCRYPT. It salts automatically and has a pepper option.'
compileJava.options.encoding = 'UTF-8'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

repositories {
  mavenCentral()
}

dependencies {
  implementation 'commons-codec:commons-codec:1.8'
  testImplementation 'junit:junit:4.12'
}

test {
  testLogging {
    showStandardStreams = true
    events "passed", "skipped", "failed", "standardOut", "standardError"
  }
  finalizedBy jacocoTestReport
}

java {
  sourceCompatibility = 1.8
  targetCompatibility = 1.8
  withJavadocJar()
  withSourcesJar()
}

jacocoTestReport {
  dependsOn test
  reports {
    xml.required = true
    html.required = false
  }
}

publishing {
  repositories {
    maven {
      def releaseRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
      def snapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
      url = isReleaseVersion ? releaseRepo : snapshotRepo
      credentials {
        username = project.hasProperty('sonatypeUsername') ? sonatypeUsername : System.getenv('SONATYPE_USERNAME')
        password = project.hasProperty('sonatypePassword') ? sonatypePassword : System.getenv('SONATYPE_PASSWORD')
      }
    }
  }

  publications {
    mavenJava(MavenPublication) {
      pom {
        name = 'jhash'
        artifactId = 'jhash'
        groupId = this.group
        version = this.version
        description = this.description
        url = 'https://amdelamar.com/jhash/'
        from components.java
        licenses {
          license {
            name = 'The Apache License, Version 2.0'
            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          }
        }
        developers {
          developer {
            id = "amdelamar"
            name = "Austin Delamar"
            email = "amdelamar@protonmail.com"
          }
        }
        scm {
          connection = 'scm:git:git@github.com:amdelamar/jhash.git'
          developerConnection = 'scm:git:git@github.com:amdelamar/jhash.git'
          url = 'https://github.com/amdelamar/jhash/'
        }
      }
    }
  }
}

signing {
  sign publishing.publications.mavenJava
}
tasks.withType(Sign) {
  onlyIf { isReleaseVersion }
}
