OSDN Git Service

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