OSDN Git Service

Create FUNDING.yml
[dictzip-java/dictzip-java.git] / build.gradle
index 360c19a..869db31 100644 (file)
@@ -2,174 +2,219 @@ import org.apache.tools.ant.filters.ReplaceTokens
 import groovy.swing.SwingBuilder
 
 plugins {
-    // github
-    id "co.riiid.gradle" version "0.4.2"
     // bintray
     id "com.jfrog.bintray" version "1.6"
+    id "com.github.spotbugs" version "1.7.1"
+    id 'maven-publish'
+    id 'signing'
 }
 
 // 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'
-  apply plugin: 'signing'
-
-  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'
-  }
+    apply plugin: 'java'
+    apply plugin: 'jacoco'
+    apply plugin: 'checkstyle'
+    apply plugin: 'com.jfrog.bintray'
+    apply plugin: 'maven'
+    apply plugin: 'maven-publish'
+    apply plugin: 'signing'
 
-  // Force prevent checkstyle/findbugs on Test.
-  task checkstyleTest(overwrite: true) << {}
-  task findbugsTest(overwrite: true) << {}
-  tasks.withType(FindBugs) {
-    reports {
-      xml.enabled = false
-      html.enabled = true
+    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'
     }
-  }
 
-  repositories {
-    jcenter()
-    mavenCentral()
-  }
+    repositories {
+        jcenter()
+    }
 
-  dependencies {
-    testCompile 'org.testng:testng:6.9.10'
-  }
+    dependencies {
+        testImplementation 'org.testng:testng:6.9.10'
+    }
+    test.useTestNG()
 
-  test {
-    useTestNG()
-  }
+    tasks.withType(JavaCompile) {
+        options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
+    }
 
-  javadoc {
-    options.locale = 'en_US'
-  }
+    javadoc {
+        options.locale = 'en_US'
+    }
 
-  task sourceJar(type: Jar) {
-      from sourceSets.main.allSource
-      classifier = 'sources'
-  }
+    task sourcesJar(type: Jar, dependsOn: classes) {
+        from sourceSets.main.allSource
+    }
 
-  task javadocJar(type: Jar, dependsOn: javadoc) {
-      classifier = 'javadoc'
-      from javadoc.destinationDir
-  }
+    task javadocJar(type: Jar, dependsOn: javadoc) {
+        from javadoc.destinationDir
+    }
 
-  artifacts {
-      archives jar
-      archives sourceJar
-      archives javadocJar
-  }
-    
-    signing {
-      sign configurations.archives
+    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'
-          userOrg = 'dictzip'
-          licenses = ['GPL-2.0+CE']
-          vcsUrl = projectUrl
-          labels = ['java','dictzip']
-          publicDownloadNumbers = true
-      }
-  }
-  task mandoc << {}
-  task githubRelease(overwrite: true) << {}
+    dependencies {
+        testImplementation 'tokyo.northside:northside-io:0.2.0'
+    }
+    version = projectVersion
+    group = projectGroup
+    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
+        }
+    }
+
+    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'
+                    }
+                }
+                scm {
+                    url = githubUrl
+                    connection = "scm:git:${githubUrl}"
+                    developerConnection = "scm:git:${githubUrl}"
+                }
+                developers {
+                    developer {
+                        id = projectOwner
+                        name = developerName
+                        email = developerEmail
+                    }
+                }
+            }
+        }
+    }
+    // maven publish to local repository.(for test)
+    uploadArchives {
+        repositories.mavenDeployer {
+            // for local maven
+            repository url: "file://$System.env.HOME/.m2/repository"
+            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
+            pom.project {
+                name = project.name
+                packaging = 'jar'
+                description = projectDesc
+                url = projectUrl
+                version = project.version
+                licenses {
+                    license {
+                        name = licenseName
+                        url = licenseUrl
+                        distribution = 'repo'
+                    }
+                }
+                scm {
+                    url = githubUrl
+                    connection = "scm:git:${githubUrl}"
+                    developerConnection = "scm:git:${githubUrl}"
+                }
+                developers {
+                    developer {
+                        id = projectOwner
+                        name = developerName
+                        email = developerEmail
+                    }
+                }
+            }
+        }
+    }
 }
 
 project(':dictzip-cli') {
-  apply plugin: 'application'
-  mainClassName = 'org.dict.zip.cli.Main'
-  applicationName = 'dictzip'
-
-  dependencies {
-    compile project(':dictzip-lib'),
-       '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'
-          userOrg = 'dictzip'
-          licenses = ['GPL-3.0']
-          vcsUrl = projectUrl
-          labels = ['java','dictzip']
-          publicDownloadNumbers = true
-      }
-  }
+    apply plugin: 'application'
+    mainClassName = 'org.dict.zip.cli.Main'
+    applicationName = 'dictzip'
 
-  task mandoc(type: Copy, overwrite: true) {
-    from "doc/dictzip.1.in"
-    into 'build/docs'
-    rename { String fileName ->
-        fileName.replace('dictzip.1.in', 'dictzip.1')
+    dependencies {
+        implementation project(':dictzip-lib'),
+           'gnu.getopt:java-getopt:1.0.13'
+        testImplementation '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'
+            userOrg = 'dictzip'
+            licenses = ['GPL-3.0']
+            vcsUrl = projectUrl
+            labels = ['java','dictzip']
+            publicDownloadNumbers = true
+        }
     }
-    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'
-              }
-          }
-      }
-  }
-  task githubRelease(overwrite: 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')
+        }
+        filter(ReplaceTokens, tokens: [copyright: projectYears, version: projectVersion])
+    }
 
-task mandoc << {}
-task bintrayUpload(overwrite: true) << {}
+    distTar {
+        compression = Compression.GZIP
+    }
+    distTar.dependsOn mandoc
 
-boolean validProperty(propertyName) {
-  try { project.property(propertyName) != null }
-  catch (MissingPropertyException) { false }
+    distributions {
+        main {
+            baseName = 'dictzip'
+            contents {
+                from('build/docs/dictzip.1') {
+                    into 'docs/man/man1'
+                }
+                from(javadocJar) {
+                    into 'docs'
+                }
+                from(sourcesJar) {
+                    into 'source'
+                }
+            }
+        }
+    }
 }
 
+// askPassword - guarantee asking only once.
+ext {
+    askPassword = ''
+}
 String askPassword(prompt) {
+    if (ext.'askPassword' != '') {
+        return ext.'askPassword'
+    }
     def keyPass = ''
     if(System.console() == null) {
         new SwingBuilder().edt {
@@ -185,36 +230,55 @@ String askPassword(prompt) {
             }
         }
     } else {
+        System.console().println()
         keyPass = System.console().readPassword(prompt)
     }
     if (keyPass.size() <= 0) {
         throw new InvalidUserDataException("You must enter the passwords to proceed.")
     }
+    ext.'askPassword' = new String(keyPass)
     new String(keyPass)
 }
 
-github {
-    owner = projectOwner
-    repo = 'dictzip-java'
-    token = githubToken
-    tagName = projectTag
-    targetCommitish = 'master'
-    name = projectTag
-    draft = true
-    body = projectReleaseBody
-    assets = [
-            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.tgz',
-            'dictzip-cli/build/distributions/dictzip-' + projectVersion + '.zip',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '.jar',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-sources.jar',
-            'dictzip-lib/build/libs/dictzip-lib-' + projectVersion + '-javadoc.jar'
-    ]
+gradle.taskGraph.whenReady { taskGraph ->
+     if (taskGraph.allTasks.any { it instanceof Sign }) {
+        allprojects {
+            ext.'signing.password' = askPassword("Enter password for PGP key ${property('signing.keyId')}: ")
+        }
+    }
 }
 
-if (gradle.startParameter.taskNames.contains('bintrayUpload')  ||
-    gradle.startParameter.taskNames.contains('githubRelease')) {
-    assert validProperty('signing.keyId'),             'properties for signing must be provided'
-    assert validProperty('signing.secretKeyRingFile'), 'properties for signing must be provided'
-    ext.'signing.password' = askPassword("Enter password for PGP key ${property('signing.keyId')}: ")
+publishing {
+  publications {
+      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")
+            }
+          }
+      }
+  }
+}
 
+signing {
+    required { gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("bintrayUpload")}
+    sign publishing.publications.mavenJava
+    sign configurations.archives
 }