-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
238 lines (202 loc) · 8.23 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
*
* Copyright (C) 2021, xyzsd (Zach Del)
*
* Licensed under either of:
*
* Apache License, Version 2.0
* (see LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
* (see LICENSE-MIT) or http://opensource.org/licenses/MIT)
*
* at your option.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
*
*/
//
// Build Configuration for Gradle 7
//
// In No Way is this a quintessential representation of a Gradle build configuration ... or is it?
//
// NOTES:
// * The root project contains no source. Sources and tests are within the subprojects.
// * Therefore, root project tasks will not execute ("NO-SOURCE").
// * Therefore, dependencies on subproject tasks must be explicitly specified (e.g., 'aggregatedDocs')
// * Various coding styles are used for defining gradle tasks, etc.... Eventually a single style should be chosen
//
//
// INFO SOURCES (in no particular order)
// * reproducible builds: https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
// * https://madhead.me/posts/no-bullshit-maven-publish/
// * https://github.com/apache/calcite-avatica/blob/master/build.gradle.kts
// * https://blog.solidsoft.pl/2021/02/26/unified-gradle-projects-releasing-to-maven-central-in-2021-migration-guide/
//
// FUTURE
// * aggregated javadocs should be published.
plugins {
id("java-library")
id("maven-publish")
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("signing")
id("com.github.spotbugs") version "4.7.1"
}
allprojects {
group = "net.xyzsd.fluent"
version = "0.70" // NOTE: publish will fail if 'staging' in name
// use 'rootProject.name' (from settings.gradle.kts) for base name
repositories {
mavenCentral()
gradlePluginPortal()
}
// to create reproducible builds ...
tasks.withType<AbstractArchiveTask>().configureEach {
isReproducibleFileOrder = true
isPreserveFileTimestamps = false
dirMode = 775
fileMode = 664
archiveVersion.set("${project.version}")
}
apply<com.github.spotbugs.snom.SpotBugsPlugin>()
configure<com.github.spotbugs.snom.SpotBugsExtension> {
// note: for plugin version 4.7.1 (spotbugs 4.2.2),
// SpotBugs will flag record class equals() methods as 'unusual'
setEffort("default")
setReportLevel("high")
ignoreFailures.set(false)
}
tasks.withType<com.github.spotbugs.snom.SpotBugsTask>().configureEach {
reports.create("xml").setEnabled(false)
reports.create("html").setEnabled(true)
}
}
configure(subprojects) {
apply<MavenPublishPlugin>()
apply<JavaLibraryPlugin>()
apply<SigningPlugin>()
pluginManager.withPlugin("java-library") {
configure<JavaPluginExtension> {
withSourcesJar()
withJavadocJar()
toolchain.languageVersion.set(JavaLanguageVersion.of(16))
}
}
tasks.withType<JavaCompile>().configureEach {
//options.compilerArgs.add("--enable-preview")
//options.compilerArgs.add("-Xlint:preview")
options.isIncremental = false
options.encoding = "UTF-8" // this is important, particularly for tests
}
tasks.withType<Javadoc>().configureEach {
val javadocOptions = options as CoreJavadocOptions
//javadocOptions.addBooleanOption("-enable-preview", true)
javadocOptions.addStringOption("source", "16")
javadocOptions.addStringOption("Xdoclint:none", "-quiet")
javadocOptions.addBooleanOption("html5",true)
options.encoding = "UTF-8"
}
tasks.withType<Jar>().configureEach {
// using automatic modules for now
manifest {
val moduleName = "${rootProject.group}.${project.name}"
attributes.set("Automatic-Module-Name", moduleName)
}
includeEmptyDirs = false
}
// tests won't run if this is not present
tasks.test {
useJUnitPlatform()
}
// if not working ('no actions') try publish to maven local for testing
configure<PublishingExtension> {
publications {
val main by creating(MavenPublication::class) {
from(components["java"])
// TODO: need aggregated docs...
pom {
artifactId = project.name
name.set("Project Fluent for Java")
description.set("A Java implementation of the Mozilla Project Fluent ")
url.set("https://github.com/xyzsd/fluent")
inceptionYear.set("2021")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
comments.set("A business-friendly OSS license")
}
license {
name.set("The MIT License")
url.set("https://opensource.org/licenses/MIT")
comments.set("A GPL/LGPL compatible OSS license")
}
}
developers {
developer {
id.set("xyzsd")
name.set("Zach Del")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/xyzsd/fluent.git")
developerConnection.set("scm:git:ssh://[email protected]:xyzsd/fluent.git")
url.set("https://github.com/xyzsd/fluent")
}
}
}
}
repositories {
maven {
name = "OSSRH"
setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
// obtained from gradle.properties in GRADLE_USER_HOME
credentials(PasswordCredentials::class)
}
}
}
}
// if 'no signatory' error, make sure GRADLE_USER_HOME is set to point to the
// the gradle.properties file containing keyID/password/etc (usually in user home dir)
configure<SigningExtension> {
val publishing: PublishingExtension by project
sign(publishing.publications)
}
}
// create aggregated javadocs (combined javadocs for all subprojects)
val aggregatedDocs by tasks.registering(Javadoc::class) {
dependsOn(":fluent-base:build")
dependsOn(":fluent-functions-cldr:build")
dependsOn(":fluent-functions-icu:build")
description = "Aggregated Javadocs"
group = JavaBasePlugin.DOCUMENTATION_GROUP
title = "${rootProject.name} API (complete) version ${project.version}"
options.encoding = "UTF-8"
val javadocOptions = options as CoreJavadocOptions
javadocOptions.addStringOption("source", "16")
javadocOptions.addBooleanOption("-enable-preview", true) // not strictly needed
javadocOptions.addStringOption("Xdoclint:none", "-quiet") // for sanity
val sourceSets = allprojects
.mapNotNull { it.extensions.findByType<SourceSetContainer>() }
.map { it.named("main") }
classpath = files(sourceSets.map { set -> set.map { it.output + it.compileClasspath } })
setSource(sourceSets.map { set -> set.map { it.allJava } })
setDestinationDir(file("$buildDir/javadoc"))
}
// archive name structure: [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
val aggregatedDocsJar by tasks.registering(Zip::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
dependsOn("aggregatedDocs")
archiveBaseName.set(rootProject.name)
archiveVersion.set("${project.version}")
archiveClassifier.set("aggregated-javadoc")
archiveExtension.set("zip")
from(aggregatedDocs)
}