OSDN Git Service

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