OSDN Git Service

ef78bf1572a97b27551574a8373c4127d2fe448e
[dictzip-java/dictzip-java.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2
3 plugins {
4     id 'java-library'
5     id 'maven-publish'
6     id 'java-library-distribution'
7     id "signing"
8     id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
9     id 'com.palantir.git-version' version "0.12.3"
10 }
11
12 // calculate version string from git tag, hash and commit distance
13 // It treat as release tag when current HEAD has a tag,
14 // and repository is clean, no modification,and no untracked files,
15 if (versionDetails().isCleanTag) {
16     // drop first 'v' from version tag
17     version = gitVersion().substring(1)
18 } else {
19     version = versionDetails().lastTag.substring(1) + '-' + versionDetails().commitDistance + '-' + versionDetails().gitHash + '-SNAPSHOT'
20 }
21
22 // common settings
23 subprojects {
24     apply plugin: 'jacoco'
25     apply plugin: 'java'
26     apply plugin: 'checkstyle'
27     apply plugin: 'maven'
28     apply plugin: 'maven-publish'
29
30     [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
31     checkstyle {
32         config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
33         ignoreFailures = true
34         toolVersion = '6.16.1'
35     }
36     version = rootProject.version
37     group = projectGroup
38
39     repositories {
40         mavenCentral()
41     }
42
43     dependencies {
44         testImplementation 'commons-io:commons-io:2.11.0'
45         testImplementation 'org.testng:testng:7.4.0'
46     }
47     test.useTestNG()
48
49     java {
50         sourceCompatibility = JavaVersion.VERSION_1_8
51         targetCompatibility = JavaVersion.VERSION_1_8
52         withSourcesJar()
53         withJavadocJar()
54     }
55
56     javadoc {
57         options.locale = 'en_US'
58     }
59
60     artifacts {
61         archives jar
62         archives sourcesJar
63         archives javadocJar
64     }
65 }
66
67 project(':dictzip-lib') {
68     apply plugin: 'java-library'
69     version = rootProject.version
70     install {
71         repositories.mavenInstaller {
72             pom.project {
73                 name = 'dictzip'
74                 packaging = 'jar'
75                 description = projectDesc
76                 url = projectUrl
77                 version = project.version
78                 licenses {
79                     license {
80                         name = licenseName
81                         url = licenseUrl
82                         distribution = 'repo'
83                     }
84                 }
85                 scm {
86                     url = githubUrl
87                     connection = "scm:git:${githubUrl}"
88                     developerConnection = "scm:git:${githubUrl}"
89                 }
90                 developers {
91                     developer {
92                         id = projectOwner
93                         name = developerName
94                         email = developerEmail
95                     }
96                 }
97             }
98         }
99     }
100
101     publishing {
102         publications {
103             mavenJava(MavenPublication) {
104                 from components.java
105                 artifactId = "dictzip"
106                 groupId = "io.github.dictzip"
107                 pom {
108                     name.set("dictzip")
109                     description.set(projectDesc)
110                     url.set(projectUrl)
111                     licenses {
112                         license {
113                             name.set("GNU General Public License v2.0 w/Classpath exception")
114                             url.set("https://www.gnu.org/software/classpath/license.html")
115                         }
116                     }
117                     scm {
118                         connection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
119                         developerConnection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
120                         url.set(projectUrl)
121                     }
122                     developers {
123                         developer {
124                             id = "miurahr"
125                             name = "Hiroshi Miura"
126                             email = "miurahr@linux.com"
127                         }
128                     }
129                     issueManagement {
130                         url.set(projectUrl + "/issues")
131                     }
132                 }
133             }
134         }
135     }
136     nexusPublishing {
137         repositories {
138             sonatype {
139                 stagingProfileId = "a1cf138b142cd"
140                 nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
141                 snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
142                 username = project.hasProperty('sonatypeUsername') ? project.property('sonatypeUsername') : System.getenv('SONATYPE_USER')
143                 password = project.hasProperty('sonatypePassword') ? project.property('sonatypePassword') : System.getenv('SONATYPE_PASS')
144             }
145         }
146     }
147
148     signing {
149         def signingKey = findProperty("signingKey")
150         def signingPassword = findProperty("signingPassword")
151         if (signingKey) {
152             useInMemoryPgpKeys(signingKey, signingPassword)
153         } else {
154             useGpgCmd()
155         }
156         sign publishing.publications.mavenJava
157     }
158     tasks.withType(Sign) {
159         def hasKey = project.hasProperty("signingKey") || project.hasProperty("signing.gnupg.keyName")
160         onlyIf { hasKey && versionDetails().isCleanTag }
161     }
162 }
163
164 project(':dictzip-cli') {
165     apply plugin: 'application'
166     mainClassName = 'org.dict.zip.cli.Main'
167     applicationName = 'dictzip'
168     version = rootProject.version
169     dependencies {
170         implementation project(':dictzip-lib')
171         implementation 'gnu.getopt:java-getopt:1.0.13'
172     }
173     task mandoc(type: Copy) {
174         from "doc/dictzip.1.in"
175         into 'build/docs'
176         rename { String fileName ->
177             fileName.replace('dictzip.1.in', 'dictzip.1')
178         }
179         filter(ReplaceTokens, tokens: [copyright: projectYears, version: project.version])
180     }
181
182     distTar {
183         compression = Compression.GZIP
184     }
185     distTar.dependsOn mandoc
186
187     distributions {
188         main {
189             baseName = 'dictzip'
190             contents {
191                 from('build/docs/dictzip.1') {
192                     into 'docs/man/man1'
193                 }
194                 from(javadocJar) {
195                     into 'docs'
196                 }
197                 from(sourcesJar) {
198                     into 'source'
199                 }
200             }
201         }
202     }
203 }