OSDN Git Service

Support publishing sonatype
[dictzip-java/dictzip-java.git] / build.gradle
1 import org.apache.tools.ant.filters.ReplaceTokens
2
3 plugins {
4     id "com.jfrog.bintray" version "1.8.5"
5     id 'java-library'
6     id "org.nosphere.gradle.github.actions" version "1.1.0"
7     id 'maven-publish'
8     id 'com.palantir.git-version' version "0.12.3"
9     id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
10     id "signing"
11 }
12
13 // calculate version string from git tag, hash and commit distance
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 // common settings
22 subprojects {
23     apply plugin: 'jacoco'
24     apply plugin: 'java'
25     apply plugin: 'checkstyle'
26     apply plugin: 'maven'
27     apply plugin: 'maven-publish'
28
29     [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
30     checkstyle {
31         config = resources.text.fromFile("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
32         ignoreFailures = true
33         toolVersion = '6.16.1'
34     }
35     version = rootProject.version
36     group = projectGroup
37
38     repositories {
39         mavenCentral()
40     }
41
42     dependencies {
43         testImplementation 'commons-io:commons-io:2.6'
44         testImplementation 'org.testng:testng:6.9.10'
45     }
46     test.useTestNG()
47
48     java {
49         sourceCompatibility = JavaVersion.VERSION_1_8
50         targetCompatibility = JavaVersion.VERSION_1_8
51         withSourcesJar()
52         withJavadocJar()
53     }
54
55     javadoc {
56         options.locale = 'en_US'
57     }
58
59     artifacts {
60         archives jar
61         archives sourcesJar
62         archives javadocJar
63     }
64 }
65
66 project(':dictzip-lib') {
67     apply plugin: 'java-library'
68     apply plugin: 'com.jfrog.bintray'
69     version = rootProject.version
70     bintray {
71         user = System.getenv('BINTRAY_USER')
72         key = System.getenv('BINTRAY_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     install {
85         repositories.mavenInstaller {
86             pom.project {
87                 name = project.name
88                 packaging = 'jar'
89                 description = projectDesc
90                 url = projectUrl
91                 version = project.version
92                 licenses {
93                     license {
94                         name = licenseName
95                         url = licenseUrl
96                         distribution = 'repo'
97                     }
98                 }
99                 scm {
100                     url = githubUrl
101                     connection = "scm:git:${githubUrl}"
102                     developerConnection = "scm:git:${githubUrl}"
103                 }
104                 developers {
105                     developer {
106                         id = projectOwner
107                         name = developerName
108                         email = developerEmail
109                     }
110                 }
111             }
112         }
113     }
114
115     publishing {
116         publications {
117             project.afterEvaluate {
118                 mavenJava(MavenPublication) {
119                     from components.java
120                     artifactId = "dictzip"
121                     groupId = projectGroup
122                     version = project.version.toString()
123                     pom {
124                         name.set(project.name)
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     }
174     nexusPublishing {
175         repositories {
176             sonatype {
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     project.afterEvaluate {
186         signing {
187         def signingKey = findProperty("signingKey")
188         def signingPassword = findProperty("signingPassword")
189         if (signingKey) {
190             useInMemoryPgpKeys(signingKey, signingPassword)
191         } else {
192             useGpgCmd()
193         }
194             sign publishing.publications.mavenJava
195         }
196         tasks.withType(Sign) {
197             def hasKey = project.hasProperty("signingKey") || project.hasProperty("signing.gnupg.keyName")
198             onlyIf { hasKey && versionDetails().isCleanTag }
199         }
200     }
201 }
202
203 project(':dictzip-cli') {
204     apply plugin: 'application'
205     mainClassName = 'org.dict.zip.cli.Main'
206     applicationName = 'dictzip'
207     version = rootProject.version
208     dependencies {
209         implementation project(':dictzip-lib')
210         implementation 'gnu.getopt:java-getopt:1.0.13'
211     }
212     task mandoc(type: Copy) {
213         from "doc/dictzip.1.in"
214         into 'build/docs'
215         rename { String fileName ->
216             fileName.replace('dictzip.1.in', 'dictzip.1')
217         }
218         filter(ReplaceTokens, tokens: [copyright: projectYears, version: project.version])
219     }
220
221     distTar {
222         compression = Compression.GZIP
223     }
224     distTar.dependsOn mandoc
225
226     distributions {
227         main {
228             baseName = 'dictzip'
229             contents {
230                 from('build/docs/dictzip.1') {
231                     into 'docs/man/man1'
232                 }
233                 from(javadocJar) {
234                     into 'docs'
235                 }
236                 from(sourcesJar) {
237                     into 'source'
238                 }
239             }
240         }
241     }
242 }