import java.text.SimpleDateFormat

Date buildTimeAndDate = new Date()
ext {
    buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
    buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
}

apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'io.codearte.nexus-staging'

jar {
    manifest {
        attributes(
                'Built-By': System.properties['user.name'],
                'Created-By': System.properties['java.version'] + " (" + System.properties['java.vendor'] + " " + System.properties['java.vm.version'] + ")",
                'Build-Date': project.buildDate,
                'Build-Time': project.buildTime,
                'Main-Class' : 'org.ajbrown.namemachine.NameMachine',
                'Specification-Title': project.name,
                'Specification-Version': project.version,
                'Specification-Vendor': project.project_vendor,
                'Implementation-Title': project.name,
                'Implementation-Version': project.version,
                'Implementation-Vendor': project.project_vendor
        )
    }
}

signing {
    sign configurations.archives
}

nexusStaging {
  username = ossrhUsername
  password = ossrhPassword
}

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 project.name
        packaging 'jar'
        artifactId 'name-machine'
        description project.project_description
        url project.project_url

        scm {
          connection 'scm:git:git@github.com:ajbrown/name-machine.git'
          developerConnection 'scm:git:git@github.com:ajbrown/name-machine.git'
          url project.project_scm
        }

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

        developers {
          developer {
            id 'ajbrown'
            name 'A.J. Brown'
            email 'aj@ajbrown.org'
          }
        }
      }
    }
  }
}
