OSDN Git Service

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