-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
120 lines (106 loc) · 3.69 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
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.4' apply false
}
final javaVersion = project.hasProperty('javaVersion') ? JavaVersion.toVersion(project.javaVersion)
: JavaVersion.VERSION_1_9
final customJreOutput = file("${buildDir}/custom-jre")
subprojects {
apply plugin: 'java'
if (project.name == 'greeter-server') {
apply plugin: 'com.github.johnrengelman.shadow'
}
sourceCompatibility = javaVersion
repositories {
jcenter()
}
dependencies {
}
}
task clean(type: Delete) {
delete 'build/custom-jre'
delete 'build/custom-jre.tar.bz2'
delete 'build/docker'
}
task build
if (javaVersion.isJava9Compatible()) {
final jdkHome = "/usr/lib/jvm/jdk-${javaVersion.majorVersion}"
subprojects {
tasks.withType(AbstractCompile) {
options.fork = true
options.forkOptions.javaHome = file(jdkHome)
options.sourcepath = files(sourceSets.main.java.srcDirs) // workaround for gradle/issues/3035
options.compilerArgs = ['--module-path', rootProject.file('greeter-protocol/build/libs')]
doLast {
def compileOpts = file('build/tmp/compileJava/java-compiler-args.txt').text.replaceAll("\n", " ")
logger.lifecycle "$jdkHome/bin/javac ${compileOpts}"
}
}
}
task customJre(dependsOn: project(':greeter-server').tasks.jar) {
ext.appModulePaths = [project(':greeter-protocol').libsDir,
project(':greeter-server').libsDir]
outputs.dir customJreOutput
ext.appModulePaths.each { inputs.dir it }
doLast {
delete customJreOutput
exec {
executable "${jdkHome}/bin/jlink"
args = ['--module-path', (["$jdkHome/jmods"] + ext.appModulePaths).grep().join(':'),
'--add-modules', 'example.greeter.server',
'--output', customJreOutput,
'--compress=2', '--strip-debug'
]
logger.lifecycle commandLine.join(' ')
}
// fix non-writable files in legal/
exec {
executable 'chmod'
args = ['u+w', '-R', customJreOutput]
}
}
}
task compressCustomJre(type: Exec, dependsOn: customJre) {
inputs.dir "$buildDir/custom-jre"
outputs.file "$buildDir/custom-jre.tar.bz2"
executable 'tar'
workingDir buildDir
args = ['cjf', 'custom-jre.tar.bz2', 'custom-jre']
}
build.dependsOn compressCustomJre
task copyFilesForDocker(type: Sync, dependsOn: [customJre]) {
from file('Dockerfile-9')
from(customJreOutput) {
into "custom-jre"
}
into 'build/docker'
}
} else {
subprojects {
sourceSets.main.java.exclude("**/module-info.java")
}
def shadowJarTask = project(':greeter-server').tasks.shadowJar
build.dependsOn shadowJarTask
task copyFilesForDocker(type: Sync, dependsOn: [shadowJarTask]) {
from file('Dockerfile')
from(shadowJarTask)
into 'build/docker'
}
}
task image(dependsOn: copyFilesForDocker) {
def imageName = "${project.name}:jre${javaVersion.majorVersion}"
group = 'Build'
description = "Build Docker image $imageName"
doLast {
exec {
executable 'docker'
args = ['build', '-t', imageName]
// args += ['--pull']
if (javaVersion.isJava9Compatible()) {
args += ['--file', 'Dockerfile-9']
}
args += ['.']
workingDir 'build/docker'
}
println "Built Docker image $imageName"
}
}