OSDN Git Service

Gradle: update build script
[dictzip-java/dictzip-java.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2 import groovy.swing.SwingBuilder
3
4 plugins {
5     // bintray
6     id "com.jfrog.bintray" version "1.6"
7     id "com.github.spotbugs" version "1.7.1"
8 }
9
10 // common settings
11 subprojects {
12     apply plugin: 'java'
13     apply plugin: 'jacoco'
14     apply plugin: 'checkstyle'
15     apply plugin: 'com.jfrog.bintray'
16     apply plugin: 'maven'
17     apply plugin: 'maven-publish'
18
19     sourceCompatibility = JavaVersion.VERSION_1_8
20     [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
21     checkstyle {
22         config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
23         ignoreFailures = true
24         toolVersion = '6.16.1'
25     }
26
27     repositories {
28         jcenter()
29     }
30
31     dependencies {
32         testImplementation 'org.testng:testng:6.9.10'
33     }
34     test.useTestNG()
35
36     tasks.withType(JavaCompile) {
37         options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
38     }
39
40     javadoc {
41         options.locale = 'en_US'
42     }
43
44     task sourcesJar(type: Jar, dependsOn: classes) {
45         from sourceSets.main.allSource
46     }
47
48     task javadocJar(type: Jar, dependsOn: javadoc) {
49         from javadoc.destinationDir
50     }
51
52     artifacts {
53         archives jar
54         archives sourcesJar
55         archives javadocJar
56     }
57
58 //    signing {
59 //        required { gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("bintrayUpload")}
60 //        sign configurations.archives
61 //    }
62 }
63
64 project(':dictzip-lib') {
65     dependencies {
66         testImplementation 'tokyo.northside:northside-io:0.2.0'
67     }
68     version = projectVersion
69     group = projectGroup
70     bintray {
71         dryRun = false
72         publish = false
73         user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
74         key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
75         configurations = ['archives']
76         pkg {
77             repo = 'maven'
78             name = 'dictzip-lib'
79             userOrg = 'dictzip'
80             licenses = ['GPL-2.0+CE']
81             vcsUrl = projectUrl
82             labels = ['java','dictzip']
83             publicDownloadNumbers = true
84         }
85     }
86
87     install {
88         repositories.mavenInstaller {
89             pom.project {
90                 name = project.name
91                 packaging = 'jar'
92                 description = projectDesc
93                 url = projectUrl
94                 version = project.version
95                 licenses {
96                     license {
97                         name = licenseName
98                         url = licenseUrl
99                         distribution = 'repo'
100                     }
101                 }
102                 scm {
103                     url = githubUrl
104                     connection = "scm:git:${githubUrl}"
105                     developerConnection = "scm:git:${githubUrl}"
106                 }
107                 developers {
108                     developer {
109                         id = projectOwner
110                         name = developerName
111                         email = developerEmail
112                     }
113                 }
114             }
115         }
116     }
117     // maven publish to local repository.(for test)
118     uploadArchives {
119         repositories.mavenDeployer {
120             // for local maven
121             repository url: "file://$System.env.HOME/.m2/repository"
122             beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
123             pom.project {
124                 name = project.name
125                 packaging = 'jar'
126                 description = projectDesc
127                 url = projectUrl
128                 version = project.version
129                 licenses {
130                     license {
131                         name = licenseName
132                         url = licenseUrl
133                         distribution = 'repo'
134                     }
135                 }
136                 scm {
137                     url = githubUrl
138                     connection = "scm:git:${githubUrl}"
139                     developerConnection = "scm:git:${githubUrl}"
140                 }
141                 developers {
142                     developer {
143                         id = projectOwner
144                         name = developerName
145                         email = developerEmail
146                     }
147                 }
148             }
149         }
150     }
151 }
152
153 project(':dictzip-cli') {
154     apply plugin: 'application'
155     mainClassName = 'org.dict.zip.cli.Main'
156     applicationName = 'dictzip'
157
158     dependencies {
159         implementation project(':dictzip-lib'),
160            'gnu.getopt:java-getopt:1.0.13'
161         testImplementation 'tokyo.northside:northside-io:0.2.0'
162     }
163     version = projectVersion
164     group = projectGroup
165     bintray {
166         user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
167         key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
168         configurations = ['archives']
169         pkg {
170             repo = 'maven'
171             name = 'dictzip-cli'
172             userOrg = 'dictzip'
173             licenses = ['GPL-3.0']
174             vcsUrl = projectUrl
175             labels = ['java','dictzip']
176             publicDownloadNumbers = true
177         }
178     }
179
180     task mandoc(type: Copy, overwrite: true) {
181         from "doc/dictzip.1.in"
182         into 'build/docs'
183         rename { String fileName ->
184             fileName.replace('dictzip.1.in', 'dictzip.1')
185         }
186         filter(ReplaceTokens, tokens: [copyright: projectYears, version: projectVersion])
187     }
188
189     distTar {
190         compression = Compression.GZIP
191     }
192     distTar.dependsOn mandoc
193
194     distributions {
195         main {
196             baseName = 'dictzip'
197             contents {
198                 from('build/docs/dictzip.1') {
199                     into 'docs/man/man1'
200                 }
201                 from(javadocJar) {
202                     into 'docs'
203                 }
204                 from(sourcesJar) {
205                     into 'source'
206                 }
207             }
208         }
209     }
210 }
211
212 // askPassword - guarantee asking only once.
213 ext {
214     askPassword = ''
215 }
216 String askPassword(prompt) {
217     if (ext.'askPassword' != '') {
218         return ext.'askPassword'
219     }
220     def keyPass = ''
221     if(System.console() == null) {
222         new SwingBuilder().edt {
223             dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) {
224                 vbox {
225                     label(text: prompt)
226                     def input1 = passwordField()
227                     button(defaultButton: true, text: 'OK', actionPerformed: {
228                         keyPass = input1.password;
229                         dispose();
230                     })
231                 }
232             }
233         }
234     } else {
235         System.console().println()
236         keyPass = System.console().readPassword(prompt)
237     }
238     if (keyPass.size() <= 0) {
239         throw new InvalidUserDataException("You must enter the passwords to proceed.")
240     }
241     ext.'askPassword' = new String(keyPass)
242     new String(keyPass)
243 }
244
245 gradle.taskGraph.whenReady { taskGraph ->
246      if (taskGraph.allTasks.any { it instanceof Sign }) {
247         allprojects {
248             ext.'signing.password' = askPassword("Enter password for PGP key ${property('signing.keyId')}: ")
249         }
250     }
251 }