/
build.gradle
435 lines (389 loc) · 13.7 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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'maven'
// ====== CONFIGURATION ===== //
//isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
ext {
// For CI environment. Optional.
jdk6BootClasspathEnv = System.getenv("JDK6_BOOT_CLASSPATH")
pythonDir = "../py4j-python/"
pythonDistDir = "${pythonDir}/dist"
webDir = "../py4j-web/"
pythonJavaDir = "${pythonDir}/py4j-java"
pythonWebDir = "${pythonDir}/doc"
pythonWebJavadocDir = "${pythonWebDir}/_static"
isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
}
// Only add spotless for JDK >= 1.8
if (JavaVersion.current().isJava8Compatible()) {
apply plugin: 'com.diffplug.gradle.spotless'
apply plugin: 'org.standardout.bnd-platform'
}
// FindBugs require JDK >= 1.7
if (JavaVersion.current().isJava7Compatible()) {
apply plugin: 'findbugs'
}
if (JavaVersion.current().isJava8Compatible()) {
platform {
fetchSources = true
eclipseHome = new File(eclipseHomePath)
featureId = 'org.py4j.feature'
featureName = 'Py4J Library'
featureVersion = bundleVersion
featureProvider = 'Py4J'
categoryId = 'py4j'
categoryName = 'Py4J'
bundle file("build/libs/py4j-java-${version}.jar"), {
bnd {
symbolicName = 'py4j-java'
bundleName = 'py4j-java'
version = bundleVersion
instruction 'DynamicImport-Package', '*'
instruction 'Import-Package', '!javax.net'
instruction 'Export-Package', 'py4j,py4j.commands,py4j.model,py4j.reflection'
instruction 'Bundle-RequiredExecutionEnvironment', 'JavaSE-1.6'
instruction 'Bundle-Description', 'Bridge between Python and Java - Java lib'
instruction 'Bundle-DocURL', 'http://www.py4j.org'
instruction 'Bundle-License', 'The New BSD License'
addQualifier = true
}
}
bundle file("build/libs/py4j-python-${version}.jar"), {
bnd {
symbolicName = 'py4j-python'
bundleName = 'py4j-python'
version = bundleVersion
instruction 'DynamicImport-Package', '*'
instruction 'Bundle-RequiredExecutionEnvironment', 'JavaSE-1.6'
instruction 'Bundle-Description', 'Bridge between Python and Java - Python lib'
instruction 'Bundle-DocURL', 'http://www.py4j.org'
instruction 'Eclipse-BundleShape', 'dir'
instruction 'Bundle-License', 'The New BSD License'
instruction 'Export-Package', ''
addQualifier = true
}
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
// Only add spotless for JDK >= 1.8
if (JavaVersion.current().isJava8Compatible()) {
classpath group: 'com.diffplug.gradle.spotless', name: 'spotless', version: '1.3.2'
classpath 'org.standardout:bnd-platform:1.3.0'
}
}
}
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.13.2'
// For Java 8 Support
if (JavaVersion.current().isJava7Compatible()) {
findbugs group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.+'
}
}
// Only add spotless for JDK >= 1.8
if (JavaVersion.current().isJava8Compatible()) {
spotless {
java {
licenseHeaderFile 'py4j.license.java'
eclipseFormatFile 'py4j.formatter.xml'
importOrderFile 'py4j.importorder'
}
}
}
// Use environment variable only if the property is not set
if (jdk6BootClasspathEnv && !jdk6BootClasspath) {
jdk6BootClasspath = jdk6BootClasspathEnv
}
if (jdk6BootClasspath) {
tasks.withType(JavaCompile) {
options.bootClasspath = "$jdk6BootClasspath"
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
options.fork = true
options.encoding = "UTF-8"
}
jacoco {
// For Java 8 Support
toolVersion = "0.7.6.201602180812"
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled true
}
}
// ====== CUSTOM TASKS ====== //
// Maven support
task createPom {
description 'Creates Py4J maven build file.'
doLast {
pom {
project {
parent {
groupId 'org.sonatype.oss'
artifactId 'oss-parent'
version '7'
}
packaging 'jar'
groupId 'net.sf.py4j'
artifactId 'py4j'
version '0.10.9.7'
name 'Py4J'
description 'Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects.'
scm {
connection 'scm:git:git@github.com:py4j/py4j.git'
developerConnection 'scm:git:git@github.com:py4j/py4j.git'
url 'git@github.com:py4j/py4j.git'
}
developers {
developer {
id 'bartdag'
name 'Barthelemy Dagenais'
url 'http://infobart.com/'
}
}
licenses {
license {
name 'The New BSD License'
url 'http://www.opensource.org/licenses/bsd-license.html'
}
}
properties {
'project.build.sourceEncoding' 'UTF-8'
'project.build.outputEncoding' 'UTF-8'
}
}
}.withXml {
asNode().appendNode('distributionManagement').appendNode('snapshotRepository').with {
appendNode('id', 'ossrh')
appendNode('url', 'https://oss.sonatype.org/content/repositories/snapshots')
}
}.withXml {
asNode().appendNode('build').appendNode('plugins').with {
appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-compiler-plugin')
appendNode('version', '3.3')
appendNode('configuration').with {
appendNode('source', '1.6')
appendNode('target', '1.6')
}
}
appendNode('plugin').with {
appendNode('groupId', 'org.sonatype.plugins')
appendNode('artifactId', 'nexus-staging-maven-plugin')
appendNode('version', '1.6.7')
appendNode('extensions', 'true')
appendNode('configuration').with {
appendNode('serverId', 'ossrh')
appendNode('nexusUrl', 'https://oss.sonatype.org')
appendNode('autoReleaseAfterClose', 'true')
}
}
appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-gpg-plugin')
appendNode('version', '1.5')
appendNode('executions').with {
appendNode('execution').with {
appendNode('id', 'sign-artifacts')
appendNode('phase', 'verify')
appendNode('goals').with {
appendNode('goal', 'sign')
}
}
}
}
appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-source-plugin')
appendNode('version', '2.2.1')
appendNode('executions').with {
appendNode('execution').with {
appendNode('id', 'attach-sources')
appendNode('goals').with {
appendNode('goal', 'jar-no-fork')
}
}
}
}
appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-javadoc-plugin')
appendNode('version', '2.9.1')
appendNode('executions').with {
appendNode('execution').with {
appendNode('id', 'attach-javadocs')
appendNode('goals').with {
appendNode('goal', 'jar')
}
}
}
}
}
}.writeTo("pom.xml")
}
}
// If someone wants to access all examples
task testsJar(type: Jar) {
description 'Creates a jar file with all test classes.'
baseName = 'py4j-tests'
from sourceSets.test.output
from sourceSets.main.output
}
task sourcesJar(type: Jar, dependsOn: classes) {
description 'Creates a sources jar.'
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
description 'Creates a jar with javadoc.'
classifier = 'javadoc'
from javadoc.destinationDir
}
task pythonSourcesJar(type: Jar) {
description 'Creates a python src jar.'
baseName = 'py4j-python'
from pythonDir
include 'src/py4j/**/*.py'
include 'LICENSE.txt'
exclude '**/__pycache__/**'
}
// We cannot use Copy because we are copying into the main directory
// And Windows does not like that:
// https://discuss.gradle.org/t/error-with-a-copy-task-on-windows/1803
task copyMainJar(type: Exec, dependsOn: jar) {
description 'Copies and rename Py4J main jar for backward compatibility.'
workingDir '.'
if (isWindows) {
commandLine 'cmd', '/c', 'copy', '/Y'
ext.baseLibPath = 'build\\libs\\'
} else {
commandLine 'cp', '-f'
ext.baseLibPath = 'build/libs/'
}
args "${baseLibPath}py4j-java-${version}.jar", "py4j${version}.jar"
}
// Make Py4J.org website and doc
task buildWeb(type: Exec) {
description 'Builds Py4J static web site and documentation.'
workingDir webDir
if (isWindows) {
commandLine 'cmd', '/c', 'make.bat'
} else {
executable 'make'
}
args 'html'
}
task copyWebPython(type: Copy, dependsOn: 'buildWeb') {
description 'Copies Py4J static web site to py4j-python directory.'
from("${webDir}/_build/html")
into pythonWebDir
}
task copyWebJavadocPython(type: Copy, dependsOn: ['javadoc', 'copyWebPython']) {
description 'Copies javadoc into Py4J static web site static directory.'
from "${buildDir}/docs"
into pythonWebJavadocDir
}
// Copy Java build to Python build for Python Source Build
task copyJavaPython(type: Copy, dependsOn: ['copyMainJar', 'javadoc', 'createPom']) {
description 'Copies py4j-java source and build files to py4j-python directory.'
from(projectDir) {
include "src"
include "ant.properties"
include "build.xml"
include "gradle.properties"
include "build.gradle"
include "pom.xml"
include "LICENSE.txt"
}
from "py4j${version}.jar"
from "${buildDir}/docs"
into pythonJavaDir
}
// Python Source Dist
task buildPythonSrc(type: Exec, dependsOn: ['copyWebJavadocPython', 'copyJavaPython']) {
description 'Builds python source distribution.'
workingDir pythonDir;
executable 'python'
args 'setup.py', 'sdist', '--formats=zip,gztar'
}
// Python Wheel Dist
task buildPythonWheel(type: Exec, dependsOn: ['copyJavaPython']) {
description 'Builds python wheel (binary) distribution.'
workingDir pythonDir;
executable 'python'
args 'setup.py', 'bdist_wheel'
}
// Python Global Dist
task buildPython(dependsOn: ['buildPythonSrc', 'buildPythonWheel']) {
description 'Builds python distributions (source and wheel).'
}
// Clean Py4J backward compatibility jar
task cleanMainJar(type: Delete) {
delete "./py4j${version}.jar"
}
// Clean web dist
task cleanWeb(type: Exec) {
workingDir webDir
if (isWindows) {
commandLine 'cmd', '/c', 'make.bat'
} else {
executable 'make'
}
args 'clean'
}
// Clean python java dir
task cleanPythonWeb(type: Delete) {
delete pythonWebDir
}
// Clean python java dir
task cleanPythonJava(type: Delete) {
delete pythonJavaDir
}
// Clean python dist
task cleanPython(type: Delete) {
delete "${pythonDir}/build"
delete "${pythonDir}/dist"
}
// ====== TASK DEPENDENCIES AND DISABLING ===== //
// For now, tests are not clean and that's fine because we want to test many
// unclean scenarios.
if (JavaVersion.current().isJava7Compatible()) {
findbugsTest.enabled = false
}
// Build all jars
artifacts {
archives sourcesJar
archives testsJar
archives javadocJar
archives pythonSourcesJar
}
assemble {
dependsOn copyMainJar
}
if (JavaVersion.current().isJava8Compatible()) {
bundles {
dependsOn assemble
}
}
clean {
dependsOn cleanMainJar
dependsOn cleanPython
dependsOn cleanWeb
dependsOn cleanPythonJava
dependsOn cleanPythonWeb
}