forked from bric3/fireplace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
259 lines (231 loc) · 9.38 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Fireplace
*
* Copyright (c) 2021, Today - Brice Dutheil
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import com.javiersc.semver.gradle.plugin.extensions.isSnapshot
fun properties(key: String, defaultValue: Any? = null) = (project.findProperty(key) ?: defaultValue).toString()
plugins {
id("com.github.hierynomus.license") version "0.16.1"
id("com.javiersc.semver.gradle.plugin") version "0.4.0-alpha.1"
id("biz.aQute.bnd.builder") version "6.4.0" apply false
`maven-publish`
}
allprojects {
group = "io.github.bric3.fireplace"
}
tasks.register("v") {
doLast {
println(project.version.toString())
}
}
val fireplaceModules = subprojects - project(":fireplace-app") - project(":fireplace-swt-experiment-app")
configure(fireplaceModules) {
apply(plugin = "java-library") // needed to get the java component
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "biz.aQute.bnd.builder")
apply(plugin = "com.javiersc.semver.gradle.plugin")
semver {
tagPrefix.set("v")
}
repositories {
mavenCentral()
}
configure<JavaPluginExtension> {
withJavadocJar()
withSourcesJar()
}
val licenseSpec = copySpec {
from("${project.rootDir}/LICENSE")
}
tasks {
withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
withType(Jar::class) {
metaInf.with(licenseSpec)
}
named<Jar>("jar") {
bundle {
val version by archiveVersion
bnd(
mapOf(
"Bundle-License" to "https://www.mozilla.org/en-US/MPL/2.0/",
"Bundle-Name" to providers.provider { project.name },
// "Bundle-Description" to project.description,
"-exportcontents" to listOf(
"!io.github.bric3.fireplace.internal.*",
"io.github.bric3.fireplace.*",
).joinToString(";"),
"-removeheaders" to "Created-By"
)
)
}
manifest.attributes(
"Implementation-Title" to providers.provider { project.name },
"Implementation-Version" to providers.provider { project.version },
"Automatic-Module-Name" to providers.provider { project.name.replace('-', '.') },
"Created-By" to "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})",
)
}
withType<PublishToMavenRepository>().configureEach {
doFirst {
logger.lifecycle("Publishing version '${[email protected]}' to ${[email protected]}")
}
}
withType<PublishToMavenLocal>().configureEach {
doFirst {
logger.lifecycle("Publishing version '${[email protected]}' locally")
}
}
}
// Doc https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials
// Details in https://github.com/bric3/fireplace/issues/25
configure<SigningExtension> {
setRequired({ gradle.taskGraph.hasTask("publish") })
useInMemoryPgpKeys(findProperty("signingKey") as? String, findProperty("signingPassword") as? String)
sign(publishing.publications)
}
// test run via (deploy on local repo 'build/publishing-repository')
// ORG_GRADLE_PROJECT_signingKey=$(cat armoredKey) ORG_GRADLE_PROJECT_signingPassword=$(cat passphrase) ./gradlew publish --console=verbose
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
val gitRepo = "https://github.com/bric3/fireplace"
pom {
name.set(project.name)
url.set(gitRepo)
scm {
connection.set("scm:git:${gitRepo}.git")
developerConnection.set("scm:git:${gitRepo}.git")
url.set(gitRepo)
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/bric3/fireplace/issues")
}
licenses {
license {
distribution.set("repo")
name.set("Mozilla Public License Version 2.0")
url.set("https://www.mozilla.org/en-US/MPL/2.0/")
}
}
developers {
developer {
id.set("bric3")
name.set("Brice Dutheil")
email.set("[email protected]")
}
}
}
// subprojects properties (like description) will be available
// after they have been configured
afterEvaluate {
pom {
description.set(project.description)
}
}
}
}
repositories {
maven {
if (providers.gradleProperty("publish.central").orNull.toBoolean()) {
val isGithubRelease =
providers.environmentVariable("GITHUB_EVENT_NAME").get().equals("release", true)
name = "central"
setUrl(isSnapshot.map { snap ->
uri(
when {
isGithubRelease && !snap -> "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
else -> "https://s01.oss.sonatype.org/content/repositories/snapshots"
}
)
})
credentials {
username = findProperty("ossrhUsername") as? String
password = findProperty("ossrhPassword") as? String
}
} else {
name = "build-dir"
url = uri("${rootProject.buildDir}/publishing-repository")
}
}
}
}
}
// Configure the right SWT dependency for the current platform
// Gradle do not offer a way to resolve a "property" like ${property}, instead it is necessary
// to configure the dependency substitution.
val os: OperatingSystem = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem()
val arch: String = providers.systemProperty("os.arch").get()
configure(listOf(project(":fireplace-swt-experiment-app"), project(":fireplace-swt-awt-bridge"))) {
configurations.all {
resolutionStrategy {
dependencySubstitution {
// Available SWT packages https://repo1.maven.org/maven2/org/eclipse/platform/
val osId = when {
os.isWindows -> "win32.win32"
os.isLinux -> "gtk.linux"
os.isMacOsX -> "cocoa.macosx"
else -> throw GradleException("Unsupported OS: $os")
}
val archId = when (arch) {
"x86_64", "amd64" -> "x86_64"
"aarch64" -> "aarch64"
else -> throw GradleException("Unsupported architecture: $arch")
}
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module("org.eclipse.platform:org.eclipse.swt.$osId.$archId:${rootProject.libs.versions.swt.get()}"))
.because("The maven property '\${osgi.platform}' that appear in the artifact coordinate is not handled by Gradle, it is required to replace the dependency")
}
}
}
}
license {
ext["year"] = "2021, Today"
ext["name"] = "Brice Dutheil"
header = file("HEADER")
strictCheck = true
ignoreFailures = false
excludes(
listOf(
"**/*.java.template",
"**/testData/*.java",
)
)
mapping(
mapOf(
"java" to "SLASHSTAR_STYLE",
"kt" to "SLASHSTAR_STYLE",
"kts" to "SLASHSTAR_STYLE",
"yaml" to "SCRIPT_STYLE",
"yml" to "SCRIPT_STYLE",
"svg" to "XML_STYLE",
"md" to "XML_STYLE",
"toml" to "SCRIPT_STYLE"
)
)
}
tasks.register("licenseCheckForProjectFiles", com.hierynomus.gradle.license.tasks.LicenseCheck::class) {
source = fileTree(project.projectDir) {
include("**/*.kt", "**/*.kts")
include("**/*.toml")
exclude("**/buildSrc/build/generated-sources/**")
}
}
tasks["license"].dependsOn("licenseCheckForProjectFiles")
tasks.register("licenseFormatForProjectFiles", com.hierynomus.gradle.license.tasks.LicenseFormat::class) {
source = fileTree(project.projectDir) {
include("**/*.kt", "**/*.kts")
include("**/*.toml")
exclude("**/buildSrc/build/generated-sources/**")
}
}
tasks["licenseFormat"].dependsOn("licenseFormatForProjectFiles")