-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
236 lines (205 loc) · 6.26 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
import java.util.regex.Matcher
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:8.3.0'
}
}
plugins {
id 'com.google.cloud.tools.jib' version '3.3.1'
}
apply plugin: 'java-library'
apply plugin: 'application'
apply plugin: 'nebula.ospackage-application'
apply plugin: 'idea'
//apply plugin: 'com.google.cloud.tools.jib'
idea.module.outputDir file("out/production/classes")
group = 'org.swimos'
description = 'Cellular Network Simulator'
version = project.property('application.version')
mainClassName = 'swim.cellular.CellularPlane'
ext.moduleName = 'swim.cellular'
ext.compilerArgs = ['-Xlint:all']
ext.swimVersion = project.property('swim.version')
// Build with `gradle -Pno-modules` to force compatibility with legacy JVMs.
def javaVersion = System.getProperty('java.version').split('\\.')
ext.jvmVersion = (javaVersion[0] as Integer) > 1 ? javaVersion[0] as Integer : javaVersion[1] as Integer
ext.useModules = !hasProperty('no-modules')
ext.moduleArgs = ['--add-modules', 'swim.meta']
repositories {
mavenCentral()
}
dependencies {
api group: 'org.swimos', name: 'swim-api', version: swimVersion
implementation group: 'org.swimos', name: 'swim-server', version: swimVersion
runtimeOnly group: 'org.swimos', name: 'swim-meta', version: swimVersion
}
afterEvaluate {
configurations {
apiElements {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
if (useModules) {
task compileModuleInfoJava(type: JavaCompile) {
dependsOn 'compileJava'
doFirst {
options.compilerArgs = [
'--module-path', compileJava.classpath.asPath,
]
}
options.compilerArgs += compilerArgs
options.encoding = 'UTF-8'
classpath = files()
source = sourceSets.main.allJava
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
destinationDirectory = compileJava.destinationDirectory
include '*module-info*'
}
classes.dependsOn compileModuleInfoJava
def dependents = configurations.api.dependencies + configurations.implementation.dependencies
def dependentProjects = dependents.findAll { it instanceof ProjectDependency }
dependentProjects.each { dependency ->
compileModuleInfoJava.dependsOn ":${dependency.name}:compileModuleInfoJava"
}
}
compileJava {
options.compilerArgs += compilerArgs
options.encoding = 'UTF-8'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
exclude '*module-info*'
}
jar {
inputs.property('moduleName', moduleName)
manifest {
attributes(
'Implementation-Title': moduleName,
'Implementation-Version': archiveVersion,
'Main-Class': mainClassName)
}
}
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar, sourcesJar
}
jib {
from {
image = "openjdk:11"
}
to {
image = "nstream/demo-cellular:${version}"
auth {
username = "$System.env.REGISTRY_USERNAME"
password = "$System.env.REGISTRY_PASSWORD"
}
}
container {
mainClass = mainClassName
ports = ['9001/tcp']
jvmFlags = ['-Dswim.config=/config/server.recon']
}
extraDirectories {
paths {
path {
// copies a single-file.xml
from = 'src/main/resources'
into = '/config'
includes = ['*.recon']
}
}
}
}
run {
dependsOn jar
if (useModules) {
doFirst {
jvmArgs += [
'--module-path', files(configurations.runtimeClasspath, jar.archivePath).asPath,
] + moduleArgs + [
'--module', "${moduleName}/${mainClassName}",
]
classpath = files()
}
}
systemProperties = System.getProperties()
}
startScripts {
inputs.property('moduleName', moduleName)
if (useModules) {
doFirst {
defaultJvmOpts += [
'-Dswim.config=/etc/swim-cellular/server.recon',
'--module-path', 'APP_HOME_LIBS',
] + moduleArgs + [
'--module', "${moduleName}/${mainClassName}",
]
classpath = files()
}
}
doLast {
def bashFile = new File(outputDir, applicationName)
String bashContent = bashFile.text
bashFile.text = bashContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('$APP_HOME/lib'))
def batFile = new File(outputDir, applicationName + ".bat")
String batContent = batFile.text
batFile.text = batContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('%APP_HOME%\\lib'))
}
}
task copyResources(type: Copy) {
from project.tasks.jar.outputs
from configurations.runtimeClasspath
into "${buildDir}/docker/libs"
}
task copyDockerfile(type: Copy) {
from "docker/Dockerfile"
into "${buildDir}/docker"
}
task dockerBuildImage() {
dependsOn copyResources
dependsOn copyDockerfile
}
ospackage {
release '1'
prefix '/opt/swim-cellular'
}
task packageDeb(type: Deb) {
maintainer = 'chris@swim.inc'
configurationFile("/etc/sysconfig/${project.name}")
preInstall "addgroup --quiet --system ${project.name}"
preInstall "adduser --quiet --system --ingroup ${project.name} --no-create-home --disabled-password ${project.name}"
postInstall "systemctl preset ${project.name} > /dev/null 2>&1"
postInstall "systemctl start ${project.name} > /dev/null 2>&1"
preUninstall "systemctl disable ${project.name} > /dev/null 2>&1"
preUninstall "systemctl stop ${project.name} > /dev/null 2>&1"
postUninstall "systemctl daemon-reload > /dev/null 2>&1"
from('pkg') {
into '/etc/systemd/system'
include '*.service'
addParentDirs false
expand project.properties
user 'root'
permissionGroup 'root'
fileMode = 0644
}
from('pkg') {
into '/etc/sysconfig'
include "${project.name}"
user 'root'
permissionGroup 'root'
fileMode = 0644
fileType CONFIG | NOREPLACE
}
}
}