OSDN Git Service

Release v0.13.0
[dictzip-java/dictzip-java.git] / build.gradle
index 77a5986..d0cee3e 100644 (file)
@@ -1,30 +1,43 @@
 import org.apache.tools.ant.filters.ReplaceTokens
 
 plugins {
-    // bintray
-    id "com.jfrog.bintray" version "1.6"
-    id "com.github.spotbugs" version "1.7.1"
-    id "org.nosphere.gradle.github.actions" version "1.1.0"
+    id 'java-library'
     id 'maven-publish'
-    id 'com.palantir.git-version' version "0.12.3"
+    id 'java-library-distribution'
+    id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
+    id 'com.palantir.git-version' version "0.13.0"
 }
 
-// Drop prefix 'v' from latest tag version.
-version = {it -> it.substring(1, it.length())}(gitVersion())
+// calculate version string from git tag, hash and commit distance
+// It treat as release tag when current HEAD has a tag,
+// and repository is clean, no modification,and no untracked files,
+if (versionDetails().isCleanTag) {
+    // drop first 'v' from version tag
+    version = gitVersion().substring(1)
+} else {
+    version = versionDetails().lastTag.substring(1) + '-' + versionDetails().commitDistance + '-' + versionDetails().gitHash + '-SNAPSHOT'
+}
+
+def props = project.file("dictzip-cli/src/main/resources/org/dict/zip/Version.properties")
+task writeVersionFile {
+    def folder = props.getParentFile()
+    if (!folder.exists()) {
+        folder.mkdirs()
+    }
+    props.delete()
+    props.text = "version=" + project.version
+}
+
+jar.dependsOn("writeVersionFile")
 
 // common settings
 subprojects {
-    apply plugin: 'java'
     apply plugin: 'jacoco'
+    apply plugin: 'java'
     apply plugin: 'checkstyle'
-    apply plugin: 'com.jfrog.bintray'
-    apply plugin: 'maven'
     apply plugin: 'maven-publish'
 
-    sourceCompatibility = JavaVersion.VERSION_1_8
-    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
     checkstyle {
-        config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
         ignoreFailures = true
         toolVersion = '6.16.1'
     }
@@ -32,19 +45,21 @@ subprojects {
     group = projectGroup
 
     repositories {
-        jcenter()
+        mavenCentral()
     }
 
     dependencies {
-        testImplementation 'org.testng:testng:6.9.10'
+        implementation "org.jetbrains:annotations:23.0.0"
+        testImplementation 'commons-io:commons-io:2.11.0'
+        testImplementation "org.junit.jupiter:junit-jupiter:5.8.2"
     }
-    test.useTestNG()
-
-    tasks.withType(JavaCompile) {
-        options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
+    test {
+        useJUnitPlatform()
     }
 
     java {
+        sourceCompatibility = JavaVersion.VERSION_1_8
+        targetCompatibility = JavaVersion.VERSION_1_8
         withSourcesJar()
         withJavadocJar()
     }
@@ -60,57 +75,83 @@ subprojects {
     }
 }
 
-project(':dictzip-lib') {
+project(':northside-io') {
+    apply plugin: 'java-library'
+    version = rootProject.version
     dependencies {
-        testImplementation 'tokyo.northside:northside-io:0.2.0'
+        implementation 'commons-io:commons-io:2.11.0'
     }
+}
+
+project(':dictzip-lib') {
+    apply plugin: 'java-library'
+    apply plugin: "signing"
     version = rootProject.version
-    bintray {
-        dryRun = false
-        publish = false
-        user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
-        key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
-        configurations = ['archives']
-        pkg {
-            repo = 'maven'
-            name = 'dictzip-lib'
-            userOrg = 'dictzip'
-            licenses = ['GPL-2.0+CE']
-            vcsUrl = projectUrl
-            labels = ['java', 'dictzip']
-            publicDownloadNumbers = true
-        }
+
+    dependencies {
+        testImplementation project(':northside-io')
     }
-    install {
-        repositories.mavenInstaller {
-            pom.project {
-                name = project.name
-                packaging = 'jar'
-                description = projectDesc
-                url = projectUrl
-                version = project.version
-                licenses {
-                    license {
-                        name = licenseName
-                        url = licenseUrl
-                        distribution = 'repo'
+
+    publishing {
+        publications {
+            mavenJava(MavenPublication) {
+                from components.java
+                artifactId = "dictzip"
+                pom {
+                    name.set("dictzip")
+                    description.set(projectDesc)
+                    url.set(projectUrl)
+                    licenses {
+                        license {
+                            name.set("GNU General Public License v2.0 w/Classpath exception")
+                            url.set("https://www.gnu.org/software/classpath/license.html")
+                        }
                     }
-                }
-                scm {
-                    url = githubUrl
-                    connection = "scm:git:${githubUrl}"
-                    developerConnection = "scm:git:${githubUrl}"
-                }
-                developers {
-                    developer {
-                        id = projectOwner
-                        name = developerName
-                        email = developerEmail
+                    scm {
+                        connection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
+                        developerConnection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
+                        url.set(projectUrl)
+                    }
+                    developers {
+                        developer {
+                            id.set("miurahr")
+                            name.set("Hiroshi Miura")
+                            email.set("miurahr@linux.com")
+                        }
+                    }
+                    issueManagement {
+                        url.set(projectUrl + "/issues")
                     }
                 }
             }
         }
     }
+    nexusPublishing {
+        repositories {
+            sonatype {
+                stagingProfileId.set("a1cf138b142cd")
+                nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
+                snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
+                username = project.hasProperty('sonatypeUsername') ? project.property('sonatypeUsername') : System.getenv('SONATYPE_USER')
+                password = project.hasProperty('sonatypePassword') ? project.property('sonatypePassword') : System.getenv('SONATYPE_PASS')
+            }
+        }
+    }
+
+    signing {
+        if (project.hasProperty("signingKey")) {
+            def signingKey = findProperty("signingKey").toString()
+            def signingPassword = findProperty("signingPassword").toString()
+            useInMemoryPgpKeys(signingKey, signingPassword)
+        } else {
+            useGpgCmd()
+        }
+        sign publishing.publications.mavenJava
+    }
+    tasks.withType(Sign) {
+        def hasKey = project.hasProperty("signingKey") || project.hasProperty("signing.gnupg.keyName")
+        onlyIf { hasKey && versionDetails().isCleanTag }
+    }
 }
 
 project(':dictzip-cli') {
@@ -119,23 +160,9 @@ project(':dictzip-cli') {
     applicationName = 'dictzip'
     version = rootProject.version
     dependencies {
-        implementation project(':dictzip-lib'),
-           'gnu.getopt:java-getopt:1.0.13'
-        testImplementation 'tokyo.northside:northside-io:0.2.0'
-    }
-    bintray {
-        user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
-        key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
-        configurations = ['archives']
-        pkg {
-            repo = 'maven'
-            name = 'dictzip-cli'
-            userOrg = 'dictzip'
-            licenses = ['GPL-3.0']
-            vcsUrl = projectUrl
-            labels = ['java', 'dictzip']
-            publicDownloadNumbers = true
-        }
+        implementation project(':dictzip-lib')
+        implementation 'gnu.getopt:java-getopt:1.0.13'
+        testImplementation project(':northside-io')
     }
     task mandoc(type: Copy) {
         from "doc/dictzip.1.in"
@@ -153,7 +180,6 @@ project(':dictzip-cli') {
 
     distributions {
         main {
-            baseName = 'dictzip'
             contents {
                 from('build/docs/dictzip.1') {
                     into 'docs/man/man1'
@@ -168,34 +194,3 @@ project(':dictzip-cli') {
         }
     }
 }
-
-publishing {
-  publications {
-     project.afterEvaluate {
-         mavenJava(MavenPublication) {
-             artifactId = "dictzip"
-             groupId = "org.dict.zip"
-             version = project.version.toString()
-             pom {
-                 name.set(project.name)
-                 description.set(projectDesc)
-                 url.set(projectUrl)
-                 licenses {
-                     license {
-                         name.set("GNU General Public License Version 2+CE")
-                         url.set("https://www.gnu.org/licenses/old-licenses/gpl-2.0")
-                     }
-                 }
-                 scm {
-                     connection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
-                     url.set("https://github.com/dictzip/dictzip-java")
-                 }
-                 issueManagement {
-                     system.set("Trac")
-                     url.set("https://github.com/dictzip/dictzip-java/issues")
-                 }
-             }
-         }
-     }
-  }
-}