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

task javadocJar(type: Jar) {
  archiveClassifier = 'javadoc'
  from javadoc.destinationDir
}

publishing {
  publications {
    mavenJava(MavenPublication) {
      logger.warn(project.group + " : " + project.name + " : " + project.version)
      logger.warn(project.description)

      groupId = project.group
      artifactId = project.name
      version = project.version

      from components.java
      artifact sourcesJar
      artifact javadocJar
      pom {
        name = project.name
        description = project.description
        url = "https://github.com/erosb/kappa"
        licenses {
          license {
            name = "Apache License, Version 2.0"
            url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
          }
        }
        developers {
          developer {
            id = 'erosb'
            name = 'Bence Erős'
            email = 'ebence88@gmail.com'
          }
        }
        scm {
          connection = "scm:git:https://github.com/erosb/kappa"
          developerConnection = "scm:git:https://github.com/erosb/kappa"
          url = "https://github.com/erosb/kappa"
        }
      }
    }
  }

  publishing {
    repositories {
      maven {
        url = project.layout.buildDirectory.dir('staging-deploy')
      }
    }
  }
}

tasks.withType(Sign) {
  onlyIf { !version.endsWith("develop") }
}

signing {
  useGpgCmd()
  sign publishing.publications.mavenJava
}

jreleaser {
  signing {
    active = 'ALWAYS'
    armored = true
  }
  release {
    github {
      commitAuthor {
        name = "Bence Eros"
        email = "ebence88@gmail.com"
      }
    }
  }
  deploy {
    maven {
      mavenCentral {
        sonatype {
          active = 'ALWAYS'
          url = 'https://central.sonatype.com/api/v1/publisher'
          stagingRepository(layout.buildDirectory.dir('staging-deploy').get().toString() + '')
        }
      }
    }
  }
}
