-
Notifications
You must be signed in to change notification settings - Fork 47
/
build.gradle
298 lines (266 loc) · 10 KB
/
build.gradle
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
buildscript {
dependencies {
classpath "org.yaml:snakeyaml:1.25"
}
}
plugins {
id "org.jetbrains.kotlin.multiplatform" apply false
id "org.jetbrains.kotlin.js" apply false
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.yaml.snakeyaml.Yaml
project.ext.letsPlotTaskGroup = 'lets-plot'
allprojects {
group = 'org.jetbrains.lets-plot'
version = "4.0.0-rc1"
// 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"
}
project.ext.jfx_platform = { -> //getJfxPlatform()
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem
if (os.isWindows()) {
return "win"
} else if (os.isLinux()) {
return "linux"
} else if (os.isMacOsX()) {
return "mac"
} else {
return "unknown"
}
}
project.ext.jfx_platform_resolved = project.ext.jfx_platform()
repositories {
mavenCentral()
}
}
// Read build settings from commandline parameters (for build_release.py script):
def readSettingsFromParameters() {
def settings = [
build_python_extension: false,
enable_python_package : false,
python : [bin_path: "", include_path: ""],
pypi : [test: [username: null, password: null],
prod: [username: null, password: null]]
]
if (project.hasProperty("build_python_extension")) {
settings.build_python_extension = project.getProperty("build_python_extension")
assert settings.build_python_extension != null
}
if (project.hasProperty("enable_python_package")) {
settings.enable_python_package = project.getProperty("enable_python_package")
assert settings.enable_python_package != null
}
if (settings.build_python_extension) {
settings.python.bin_path = project.getProperty("python_bin_path")
settings.python.include_path = project.getProperty("python_include_path")
assert !settings.python.bin_path.isEmpty()
assert !settings.python.include_path.isEmpty()
}
return settings
}
// Read build settings from build_settings.yml:
def readSettingsFromYaml() {
def build_settings_file = new File(rootDir, "build_settings.yml")
if (!build_settings_file.canRead()) {
throw new GradleException("Couldn't read build_settings.yml")
}
def settings = new Yaml().load(build_settings_file.newInputStream())
if (settings.build_python_extension) {
assert settings.python.include_path != null
}
if (settings.enable_python_package) {
assert settings.build_python_extension
assert settings.python.bin_path != null
}
return settings
}
// Get Python's arch to define Kotlin targets:
def getPythonArch() {
def python_bin_path = project.buildSettings.python.bin_path
def getArchOutput = new ByteArrayOutputStream()
exec {
commandLine "${python_bin_path}/python",
"-c",
"import platform; print(platform.machine())"
standardOutput = getArchOutput
}
return getArchOutput.toString().trim()
}
// For build_release.py settings will be read from commandline parameters.
// If not, settings will be read from build_settings.yml.
if (project.hasProperty("build_release")) {
project.ext.buildSettings = readSettingsFromParameters()
} else {
project.ext.buildSettings = readSettingsFromYaml() as LinkedHashMap
}
// Read Python arch from commandline parameter if used:
if (project.hasProperty("build_arch")) {
project.ext.pythonArch = project.getProperty("build_arch")
assert !project.pythonArch.isEmpty()
} else if (project.buildSettings.build_python_extension) {
project.ext.pythonArch = getPythonArch()
}
// Maven publication settings
// define local Maven Repository path:
project.ext.localMavenRepository = "$rootDir/.maven-publish-dev-repo"
// define Sonatype nexus repository manager settings:
nexusPublishing {
repositories {
maven {
username = project.buildSettings?.sonatype?.username
password = project.buildSettings?.sonatype?.password
stagingProfileId = "11c25ff9a87b89"
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
// "JavaDoc" artifact for all publications.
task jarJavaDocs(type: Jar) {
group project.letsPlotTaskGroup
classifier 'javadoc'
from("$rootDir/README.md")
}
// Publish some sub-projects as Kotlin Multiproject libraries.
task publishLetsPlotCoreModulesToMavenLocalRepository {
group project.letsPlotTaskGroup
}
task publishLetsPlotCoreModulesToMavenRepository {
group project.letsPlotTaskGroup
}
subprojects {
// Configure Kotlin targets.
// List of modules used in Python native extension:
if (name in [
'commons',
'datamodel',
'plot-base',
'plot-builder',
'plot-stem',
'platf-native',
'demo-and-test-shared',
]) {
apply plugin: "org.jetbrains.kotlin.multiplatform"
def currentOs = DefaultNativePlatform.getCurrentOperatingSystem()
kotlin {
if (project.buildSettings.build_python_extension) {
if (currentOs.macOsX & project.pythonArch == "x86_64") {
macosX64()
} else if (currentOs.macOsX & project.pythonArch == "arm64") {
if (project.hasProperty("build_release")) {
macosX64()
macosArm64()
} else {
macosArm64()
}
} else if (currentOs.linux) {
if (project.hasProperty("build_release")) {
linuxX64()
linuxArm64()
} else if (project.pythonArch == "x86_64") {
linuxX64()
}
} else if (currentOs.windows) {
mingwX64()
} else {
throw new Exception("Unsupported platform.")
}
}
}
}
// Configure publishing core artifacts.
if (name in [
'commons',
'datamodel',
'canvas',
'gis',
'livemap',
'plot-base',
'plot-builder',
'plot-stem',
'plot-livemap',
'platf-awt',
'platf-batik',
'platf-jfx-swing',
'deprecated-in-v4'
]) {
apply plugin: "org.jetbrains.kotlin.multiplatform"
kotlin.jvm {} // for `jvmSourcesJar` task
apply plugin: "maven-publish"
apply plugin: "signing"
// Do not publish 'native' targets.
def publications_to_publish = ["jvm", "js", "kotlinMultiplatform", "metadata"]
publishing {
publications {
withType(MavenPublication) {
if (name in publications_to_publish) {
// Configure this publication.
artifact rootProject.jarJavaDocs
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 = "lets-plot@jetbrains.com"
}
}
scm {
url = "https://github.com/JetBrains/lets-plot"
}
}
}
}
}
repositories {
mavenLocal {
url = uri(project.localMavenRepository)
}
}
}
afterEvaluate {
// Add LICENSE file to the META-INF folder inside published JAR files
jvmJar {
metaInf {
from("$rootDir") {
include "LICENSE"
}
}
}
// Configure artifacts signing process.
def publications_to_sign = []
for (task in it.tasks.withType(PublishToMavenRepository)) {
if (task.getPublication().name in publications_to_publish) {
def repoName = task.repository.name
if (repoName == "MavenLocal") {
publishLetsPlotCoreModulesToMavenLocalRepository.dependsOn += task
} else if (repoName == "maven") {
publishLetsPlotCoreModulesToMavenRepository.dependsOn += task
publications_to_sign += task.getPublication()
} else {
throw new IllegalStateException("Repository expected: 'MavenLocal' or 'maven' but was: '$repoName'.")
}
}
}
// Sign artifacts.
publications_to_sign.each {
signing.sign(it)
}
}
}
}