-
Notifications
You must be signed in to change notification settings - Fork 49
/
build.gradle.kts
336 lines (293 loc) · 11.3 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
* Copyright (c) 2024. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
import java.util.*
import org.gradle.internal.os.OperatingSystem
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException
plugins {
kotlin("multiplatform") apply false
kotlin("js") apply false
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
fun ExtraPropertiesExtension.getOrNull(name: String): Any? = if (has(name)) { get(name) } else { null }
val os: OperatingSystem = OperatingSystem.current()
val letsPlotTaskGroup by extra { "lets-plot" }
allprojects {
group = "org.jetbrains.lets-plot"
version = "4.3.4-SNAPSHOT" // see also: python-package/lets_plot/_version.py
// Generate JVM 1.8 bytecode
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
fun getJfxPlatform(): String {
if (os.isWindows()) {
return "win"
} else if (os.isLinux()) {
return "linux"
} else if (os.isMacOsX()) {
return "mac"
} else {
return "unknown"
}
}
val jfxPlatformResolved by extra { getJfxPlatform() }
repositories {
mavenCentral()
}
}
// Read build settings from commandline parameters (for build_release.py script):
fun readPropertiesFromParameters() {
val properties = Properties()
if (project.hasProperty("enable_python_package")) {
properties["enable_python_package"] = project.property("enable_python_package")
}
if (properties.getProperty("enable_python_package").toBoolean()) {
properties["python.bin_path"] = project.property("python.bin_path")
properties["python.include_path"] = project.property("python.include_path")
}
if (!os.isWindows) {
properties["architecture"] = project.property("architecture")
}
for (property in properties) {
extra[property.key as String] = property.value
}
}
// Read build settings from local.properties:
fun readPropertiesFromFile() {
val properties = Properties()
val localPropsFileName = "local.properties"
if (project.file(localPropsFileName).exists()) {
properties.load(project.file(localPropsFileName).inputStream())
} else {
throw FileNotFoundException(
"${localPropsFileName} file not found!\n" +
"Check ${localPropsFileName}_template file for the template."
)
}
if (!os.isWindows) {
// Only 64bit version can be built for Windows, so the arch parameter is not needed and may not be set.
assert(properties["architecture"] != null)
}
if (properties.getProperty("enable_python_package").toBoolean()) {
val pythonBinPath = properties["python.bin_path"]
val pythonIncludePath = properties["python.include_path"]
assert(pythonBinPath != null)
assert(pythonIncludePath != null)
if (!os.isWindows) {
val getArchOutput = ByteArrayOutputStream()
exec {
commandLine(
"${pythonBinPath}/python",
"-c",
"import platform; print(platform.machine())"
)
standardOutput = getArchOutput
}
val currentPythonArch = getArchOutput.toString().trim()
if (currentPythonArch != properties["architecture"]) {
throw IllegalArgumentException(
"Project and Python architectures don't match!\n" +
" - Value, from your '${localPropsFileName}' file: ${properties["architecture"]}\n" +
" - Your Python architecture: ${currentPythonArch}\n" +
"Check your '${localPropsFileName}' file."
)
}
}
}
for (property in properties) {
extra[property.key as String] = property.value
}
}
// For build_release.py settings will be read from commandline parameters.
// In other cases, settings will be read from local.properties.
if (project.hasProperty("build_release")) {
readPropertiesFromParameters()
} else {
readPropertiesFromFile()
}
// Maven publication settings:
// define local Maven Repository path:
val localMavenRepository by extra { "$rootDir/.maven-publish-dev-repo" }
// define Sonatype nexus repository manager settings:
val sonatypeUsername = extra.getOrNull("sonatype.username")?: ""
val sonatypePassword = extra.getOrNull("sonatype.password")?: ""
val sonatypeProfileID = extra.getOrNull("sonatype.profileID")?: ""
nexusPublishing {
repositories {
register("maven") {
username.set(sonatypeUsername as String)
password.set(sonatypePassword as String)
stagingProfileId.set(sonatypeProfileID as String)
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
// Publish some sub-projects as Kotlin Multi-project libraries.
val publishLetsPlotCoreModulesToMavenLocalRepository by tasks.registering {
group=letsPlotTaskGroup
}
val publishLetsPlotCoreModulesToMavenRepository by tasks.registering {
group=letsPlotTaskGroup
}
// Generating JavaDoc task for each publication task.
// Fixes "Task ':canvas:publishJsPublicationToMavenRepository' uses this output of task ':canvas:signJvmPublication'
// without declaring an explicit or implicit dependency" error.
// Issues:
// - https://github.com/gradle-nexus/publish-plugin/issues/208
// - https://github.com/gradle/gradle/issues/26091
//
fun getJarJavaDocsTask(distributeName:String): TaskProvider<Jar> {
return tasks.register<Jar>("${distributeName}JarJavaDoc") {
archiveClassifier.set("javadoc")
from("$rootDir/README.md")
archiveBaseName.set(distributeName)
}
}
subprojects {
val pythonExtensionModules = listOf(
"commons",
"datamodel",
"plot-base",
"plot-builder",
"plot-stem",
"platf-native",
"demo-and-test-shared"
)
val projectArchitecture = rootProject.extra.getOrNull("architecture")
if (name in pythonExtensionModules) {
apply(plugin = "org.jetbrains.kotlin.multiplatform")
configure<KotlinMultiplatformExtension> {
if (os.isMacOsX && projectArchitecture == "x86_64") {
macosX64()
} else if (os.isMacOsX && projectArchitecture == "arm64") {
if (project.hasProperty("build_release")) {
macosX64()
macosArm64()
} else {
macosArm64()
}
} else if (os.isLinux) {
if (project.hasProperty("build_release")) {
linuxX64()
linuxArm64()
} else if (projectArchitecture == "x86_64") {
linuxX64()
}
} else if (os.isWindows) {
mingwX64()
} else {
throw Exception("Unsupported platform! Check project settings.")
}
}
}
val coreModulesForPublish = listOf(
"commons",
"datamodel",
"canvas",
"gis",
"livemap",
"plot-base",
"plot-builder",
"plot-stem",
"plot-livemap",
"platf-awt",
"platf-batik",
"platf-jfx-swing",
"deprecated-in-v4"
)
if (name in coreModulesForPublish) {
apply(plugin = "org.jetbrains.kotlin.multiplatform")
apply(plugin = "maven-publish")
apply(plugin = "signing")
// For `jvmSourcesJar` task:
configure<KotlinMultiplatformExtension> {
jvm()
}
// Do not publish 'native' targets:
val publicationsToPublish = listOf("jvm", "js", "kotlinMultiplatform", "metadata")
configure<PublishingExtension> {
publications {
withType(MavenPublication::class) {
if (name in publicationsToPublish) {
// Configure this publication.
artifact(getJarJavaDocsTask("${name}-${project.name}"))
pom {
name = "Lets-Plot core artifact"
description = "A part of the Lets-Plot library."
url = "https://github.com/JetBrains/lets-plot"
licenses {
license {
name = "MIT"
url = "https://raw.githubusercontent.com/JetBrains/lets-plot/master/LICENSE"
}
}
developers {
developer {
id = "jetbrains"
name = "JetBrains"
email = "[email protected]"
}
}
scm {
url = "https://github.com/JetBrains/lets-plot"
}
}
}
}
}
repositories {
mavenLocal {
url = uri(localMavenRepository)
}
}
}
afterEvaluate {
// Add LICENSE file to the META-INF folder inside published JAR files.
tasks.named<Jar>("jvmJar") {
metaInf {
from("$rootDir") {
include("LICENSE")
}
}
}
// Configure artifacts signing process for release versions.
val publicationsToSign = mutableListOf<Publication>()
for (task in tasks.withType(PublishToMavenRepository::class)) {
if (task.publication.name in publicationsToPublish) {
val repoName = task.repository.name
if (repoName == "MavenLocal") {
publishLetsPlotCoreModulesToMavenLocalRepository.configure {
dependsOn += task
}
} else if (repoName == "maven") {
publishLetsPlotCoreModulesToMavenRepository.configure {
dependsOn += task
}
publicationsToSign.add(task.publication)
} else {
throw IllegalStateException("Repository expected: 'MavenLocal' or 'maven' but was: '$repoName'.")
}
}
}
// Sign artifacts.
publicationsToSign.forEach {
if (!project.version.toString().contains("SNAPSHOT")) {
configure<SigningExtension> {
sign(it)
}
}
}
}
}
}