OSDN Git Service

Gradle: add stageprofileid
[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 "com.jfrog.bintray" version "1.8.5"
9     id "org.nosphere.gradle.github.actions" version "1.1.0"
10     id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
11     id "io.freefair.maven-central.validate-poms" version "5.3.0"
12     id 'com.palantir.git-version' version "0.12.3"
13 }
14
15 // calculate version string from git tag, hash and commit distance
16 if (versionDetails().isCleanTag) {
17     // drop first 'v' from version tag
18     version = gitVersion().substring(1)
19 } else {
20     version = versionDetails().lastTag.substring(1) + '-' + versionDetails().commitDistance + '-' + versionDetails().gitHash + '-SNAPSHOT'
21 }
22
23 // common settings
24 subprojects {
25     apply plugin: 'jacoco'
26     apply plugin: 'java'
27     apply plugin: 'checkstyle'
28     apply plugin: 'maven'
29     apply plugin: 'maven-publish'
30
31     [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
32     checkstyle {
33         config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
34         ignoreFailures = true
35         toolVersion = '6.16.1'
36     }
37     version = rootProject.version
38     group = projectGroup
39
40     repositories {
41         mavenCentral()
42     }
43
44     dependencies {
45         testImplementation 'commons-io:commons-io:2.6'
46         testImplementation 'org.testng:testng:6.9.10'
47     }
48     test.useTestNG()
49
50     java {
51         sourceCompatibility = JavaVersion.VERSION_1_8
52         targetCompatibility = JavaVersion.VERSION_1_8
53         withSourcesJar()
54         withJavadocJar()
55     }
56
57     javadoc {
58         options.locale = 'en_US'
59     }
60
61     artifacts {
62         archives jar
63         archives sourcesJar
64         archives javadocJar
65     }
66 }
67
68 project(':dictzip-lib') {
69     apply plugin: 'java-library'
70     apply plugin: 'com.jfrog.bintray'
71     version = rootProject.version
72     bintray {
73         user = System.getenv('BINTRAY_USER')
74         key = System.getenv('BINTRAY_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     install {
87         repositories.mavenInstaller {
88             pom.project {
89                 name = 'dictzip'
90                 packaging = 'jar'
91                 description = projectDesc
92                 url = projectUrl
93                 version = project.version
94                 licenses {
95                     license {
96                         name = licenseName
97                         url = licenseUrl
98                         distribution = 'repo'
99                     }
100                 }
101                 scm {
102                     url = githubUrl
103                     connection = "scm:git:${githubUrl}"
104                     developerConnection = "scm:git:${githubUrl}"
105                 }
106                 developers {
107                     developer {
108                         id = projectOwner
109                         name = developerName
110                         email = developerEmail
111                     }
112                 }
113             }
114         }
115     }
116
117     publishing {
118         publications {
119             mavenJava(MavenPublication) {
120                 from components.java
121                 artifactId = "dictzip"
122                 groupId = "io.github.dictzip"
123                 pom {
124                     name.set("dictzip")
125                     description.set(projectDesc)
126                     url.set(projectUrl)
127                     licenses {
128                         license {
129                             name.set("GNU General Public License Version 2+CE")
130                             url.set("https://www.gnu.org/licenses/old-licenses/gpl-2.0")
131                         }
132                     }
133                     scm {
134                         connection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
135                         developerConnection.set("scm:git:git://github.com/dictzip/dictzip-java.git")
136                         url.set(projectUrl)
137                     }
138                     developers {
139                         developer {
140                             id = "miurahr"
141                             name = "Hiroshi Miura"
142                             email = "miurahr@linux.com"
143                         }
144                     }
145                     issueManagement {
146                         url.set(projectUrl + "/issues")
147                     }
148                 }
149             }
150         }
151     }
152     repositories {
153         maven {
154             name = "GitHubPackages"
155             url = "https://maven.pkg.github.com/dictzip/dictzip-java"
156             credentials {
157                 username = System.getenv("GITHUB_ACTOR")
158                 password = System.getenv("GITHUB_TOKEN")
159             }
160         }
161         maven {
162             name 'AzurePackages'
163             url 'https://pkgs.dev.azure.com/miurahr/github/_packaging/maven/maven/v1'
164             credentials(PasswordCredentials) {
165                 username = System.getenv("AZURE_USER")
166                 password = System.getenv("AZURE_TOKEN")
167             }
168             authentication {
169                 basic(BasicAuthentication)
170             }
171         }
172     }
173     nexusPublishing {
174         repositories {
175             sonatype {
176                 stagingProfileId = "a1cf138b142cd"
177                 nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
178                 snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
179                 username = project.hasProperty('sonatypeUsername') ? project.property('sonatypeUsername') : System.getenv('SONATYPE_USER')
180                 password = project.hasProperty('sonatypePassword') ? project.property('sonatypePassword') : System.getenv('SONATYPE_PASS')
181             }
182         }
183     }
184
185     signing {
186         def signingKey = findProperty("signingKey")
187         def signingPassword = findProperty("signingPassword")
188         if (signingKey) {
189             useInMemoryPgpKeys(signingKey, signingPassword)
190         } else {
191             useGpgCmd()
192         }
193             sign publishing.publications.mavenJava
194         }
195         tasks.withType(Sign) {
196             def hasKey = project.hasProperty("signingKey") || project.hasProperty("signing.gnupg.keyName")
197             onlyIf { hasKey && versionDetails().isCleanTag }
198         }
199     }
200
201 project(':dictzip-cli') {
202     apply plugin: 'application'
203     mainClassName = 'org.dict.zip.cli.Main'
204     applicationName = 'dictzip'
205     version = rootProject.version
206     dependencies {
207         implementation project(':dictzip-lib')
208         implementation 'gnu.getopt:java-getopt:1.0.13'
209     }
210     task mandoc(type: Copy) {
211         from "doc/dictzip.1.in"
212         into 'build/docs'
213         rename { String fileName ->
214             fileName.replace('dictzip.1.in', 'dictzip.1')
215         }
216         filter(ReplaceTokens, tokens: [copyright: projectYears, version: project.version])
217     }
218
219     distTar {
220         compression = Compression.GZIP
221     }
222     distTar.dependsOn mandoc
223
224     distributions {
225         main {
226             baseName = 'dictzip'
227             contents {
228                 from('build/docs/dictzip.1') {
229                     into 'docs/man/man1'
230                 }
231                 from(javadocJar) {
232                     into 'docs'
233                 }
234                 from(sourcesJar) {
235                     into 'source'
236                 }
237             }
238         }
239     }
240 }