OSDN Git Service

Merge remote-tracking branch 'origin/topic/miurahr/fix-dictzip-outputstream' into...
[dictzip-java/dictzip-java.git] / build.gradle
index 440cdcf..25d8979 100644 (file)
 import org.apache.tools.ant.filters.ReplaceTokens
 
 plugins {
-    // github
-    id "co.riiid.gradle" version "0.4.2"
-    // bintray
-    id "com.jfrog.bintray" version "1.6"
+    id 'java-library'
+    id 'maven-publish'
+    id 'java-library-distribution'
+    id "signing"
+    id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
+    id 'com.palantir.git-version' version "0.12.3"
+}
+
+// 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'
 }
 
 // common settings
 subprojects {
-  apply plugin: 'java'
-  apply plugin: 'jacoco'
-  apply plugin: 'checkstyle'
-  apply plugin: 'findbugs'
-  apply plugin: 'co.riiid.gradle'
-  apply plugin: 'com.jfrog.bintray'
-  apply plugin: 'maven'
-
-  sourceCompatibility = jdkVersion
-  targetCompatibility = jdkVersion
-  [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
-  [compileJava, compileTestJava]*.options*.bootClasspath = "$JDK_HOME/jre/lib/rt.jar"
-  checkstyle {
-    config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
-    ignoreFailures = true
-    toolVersion = '6.16.1'
-  }
-
-  // Force prevent checkstyle/findbugs on Test.
-  task checkstyleTest(overwrite: true) << {}
-  task findbugsTest(overwrite: true) << {}
-  tasks.withType(FindBugs) {
-    reports {
-      xml.enabled = false
-      html.enabled = true
+    apply plugin: 'jacoco'
+    apply plugin: 'java'
+    apply plugin: 'checkstyle'
+    apply plugin: 'maven-publish'
+
+    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
+    checkstyle {
+        config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
+        ignoreFailures = true
+        toolVersion = '6.16.1'
     }
-  }
+    version = rootProject.version
+    group = projectGroup
 
-  repositories {
-    jcenter()
-    mavenCentral()
-  }
-
-  dependencies {
-    testCompile 'org.testng:testng:6.9.10'
-  }
+    repositories {
+        mavenCentral()
+    }
 
-  test {
-    useTestNG()
-  }
+    dependencies {
+        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 {
+        useJUnitPlatform()
+    }
 
-  task sourceJar(type: Jar) {
-      from sourceSets.main.allSource
-      classifier = 'sources'
-  }
+    java {
+        sourceCompatibility = JavaVersion.VERSION_1_8
+        targetCompatibility = JavaVersion.VERSION_1_8
+        withSourcesJar()
+        withJavadocJar()
+    }
 
-  task javadocJar(type: Jar, dependsOn: javadoc) {
-      classifier = 'javadoc'
-      from javadoc.destinationDir
-  }
+    javadoc {
+        options.locale = 'en_US'
+    }
 
-  artifacts {
-      archives jar
-      archives sourceJar
-      archives javadocJar
-  }
+    artifacts {
+        archives jar
+        archives sourcesJar
+        archives javadocJar
+    }
 }
 
 project(':dictzip-lib') {
-  dependencies {
-    testCompile 'tokyo.northside:northside-io:0.2.0'
-  }
-  version = projectVersion
-  group = projectGroup
-  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-lib'
-          licenses = ['GPL-2.0+CE']
-          vcsUrl = projectUrl
-          labels = ['java','dictzip']
-          publicDownloadNumbers = true
-      }
-  }
-  task mandoc << {}
-}
-
-project(':dictzip-cli') {
-  apply plugin: 'application'
-  mainClassName = 'org.dict.zip.cli.Main'
-  applicationName = 'DictZip'
-
-  dependencies {
-    compile project(':dictzip-lib'),
-       'commons-codec:commons-codec:1.10',
-       'gnu.getopt:java-getopt:1.0.13'
-    testCompile 'tokyo.northside:northside-io:0.2.0'
-  }
-  version = projectVersion
-  group = projectGroup
-  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'
-          licenses = ['GPL-3.0']
-          vcsUrl = projectUrl
-          labels = ['java','dictzip']
-          publicDownloadNumbers = true
-      }
-  }
-
-  task mandoc(type: Copy, overwrite: true) {
-    from "doc/dictzip.1.in"
-    into 'build/docs'
-    rename { String fileName ->
-        fileName.replace('dictzip.1.in', 'dictzip.1')
+    apply plugin: 'java-library'
+    version = rootProject.version
+    publishing {
+        publications {
+            mavenJava(MavenPublication) {
+                from components.java
+                artifactId = "dictzip"
+                groupId = "io.github.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 {
+                        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 = "miurahr"
+                            name = "Hiroshi Miura"
+                            email = "miurahr@linux.com"
+                        }
+                    }
+                    issueManagement {
+                        url.set(projectUrl + "/issues")
+                    }
+                }
+            }
+        }
+    }
+    nexusPublishing {
+        repositories {
+            sonatype {
+                stagingProfileId = "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')
+            }
+        }
     }
-    filter(ReplaceTokens, tokens: [copyright: projectYears, version: projectVersion])
-  }
-
-  distTar {
-    compression = Compression.GZIP
-  }
-  distTar.dependsOn mandoc
 
-  distributions {
-      main {
-          baseName = 'dictzip'
-          contents {
-              from('build/docs/dictzip.1') {
-                  into 'docs/man/man1'
-              }
-              from(javadocJar) {
-                  into 'docs'
-              }
-              from(sourceJar) {
-                  into 'source'
-              }
-          }
-      }
-  }
+    signing {
+        def signingKey = findProperty("signingKey")
+        def signingPassword = findProperty("signingPassword")
+        if (signingKey) {
+            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 }
+    }
 }
 
-task mandoc << {}
+project(':dictzip-cli') {
+    apply plugin: 'application'
+    mainClassName = 'org.dict.zip.cli.Main'
+    applicationName = 'dictzip'
+    version = rootProject.version
+    dependencies {
+        implementation project(':dictzip-lib')
+        implementation 'gnu.getopt:java-getopt:1.0.13'
+    }
+    task mandoc(type: Copy) {
+        from "doc/dictzip.1.in"
+        into 'build/docs'
+        rename { String fileName ->
+            fileName.replace('dictzip.1.in', 'dictzip.1')
+        }
+        filter(ReplaceTokens, tokens: [copyright: projectYears, version: project.version])
+    }
 
-if (gradle.startParameter.taskNames.contains('bintrayUpload')  ||
-    gradle.startParameter.taskNames.contains('githubRelease')) {
-  apply from: 'build.publish.gradle'
+    distTar {
+        compression = Compression.GZIP
+    }
+    distTar.dependsOn mandoc
+
+    distributions {
+        main {
+            contents {
+                from('build/docs/dictzip.1') {
+                    into 'docs/man/man1'
+                }
+                from(javadocJar) {
+                    into 'docs'
+                }
+                from(sourcesJar) {
+                    into 'source'
+                }
+            }
+        }
+    }
 }