-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdu-cloud.gradle
More file actions
317 lines (263 loc) · 9.04 KB
/
sdu-cloud.gradle
File metadata and controls
317 lines (263 loc) · 9.04 KB
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
import java.nio.channels.*
import java.nio.file.Files
import java.net.URL
import java.io.FileOutputStream
//
// Configuration
//
buildscript { // TODO Not how you should do stuff like this. Still works though.
ext.setDefaultConfig = { String key, String value ->
ExtraPropertiesExtension ext = ext
if (!ext.has(key)) ext.set(key, value)
}
setDefaultConfig("dokka_version", "0.9.18")
setDefaultConfig("ktor_version", "1.2.3")
setDefaultConfig("kotlin_version", "1.3.41")
setDefaultConfig("junit_version", "4.12")
setDefaultConfig("mockk_version", "1.9.3")
setDefaultConfig("detekt_version", "1.2.2")
setDefaultConfig("ktor_engine", "netty")
}
repositories {
jcenter()
}
//
// Build scripts
//
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}"
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
}
}
apply plugin: io.gitlab.arturbosch.detekt.DetektPlugin
detekt {
toolVersion = "$detekt_version"
input = files("src/main/kotlin")
filters = ".*/resources/.*,.*/build/.*"
// https://stackoverflow.com/a/921400
def currentVersion = "v0.2.20"
URL website = new URL("https://raw.githubusercontent.com/SDU-eScience/GradleBootstrap/$currentVersion/detekt.yml")
ReadableByteChannel rbc = Channels.newChannel(website.openStream())
def outputFile = Files.createTempFile("detekt", ".yml").toFile()
FileOutputStream fos = new FileOutputStream(outputFile)
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE)
config = files(outputFile.absolutePath)
}
//
// Kotlin
//
apply plugin: 'idea'
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
apply plugin: org.jetbrains.kotlin.noarg.gradle.KotlinJpaSubplugin
sourceCompatibility = 1.8
compileKotlin { kotlinOptions.jvmTarget = "1.8" }
compileTestKotlin { kotlinOptions.jvmTarget = "1.8" }
kotlin.sourceSets.all {
it.languageSettings {
progressiveMode = true
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
//
// Default repositories
//
repositories {
mavenCentral()
mavenLocal()
maven { url "https://kotlin.bintray.com/ktor" }
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
}
//
// Private SDUCloud maven repositories
//
repositories {
def username = System.getenv("ESCIENCE_MVN_USER") ?: eScienceCloudUser
def password = System.getenv("ESCIENCE_MVN_PASSWORD") ?: eScienceCloudPassword
maven {
url("https://archiva.dev.cloud.sdu.dk/repository/internal")
credentials {
it.username(username)
it.password(password)
}
}
maven {
url("https://archiva.dev.cloud.sdu.dk/repository/snapshots")
credentials {
it.username(username)
it.password(password)
}
}
}
apply plugin: 'maven-publish'
publishing {
def username = System.getenv("ESCIENCE_MVN_USER") ?: eScienceCloudUser
def password = System.getenv("ESCIENCE_MVN_PASSWORD") ?: eScienceCloudPassword
repositories {
it.maven {
def resolvedUrl = "https://archiva.dev.cloud.sdu.dk/repository/"
if (project.version.endsWith("-SNAPSHOT")) resolvedUrl += "snapshots"
else resolvedUrl += "internal"
url(resolvedUrl)
credentials {
it.username(username)
it.password(password)
}
}
}
}
//
// Ktor
//
dependencies {
def withoutLogback = { exclude group: 'ch.qos.logback', module: 'logback-classic' }
compile group: 'io.ktor', name: "ktor-server-${ktor_engine}", version: "$ktor_version", withoutLogback
}
//
// Testing
//
dependencies {
def withoutLogback = { exclude group: 'ch.qos.logback', module: 'logback-classic' }
testCompile "junit:junit:$junit_version"
testCompile "io.mockk:mockk:$mockk_version"
testCompile "io.ktor:ktor-server-test-host:$ktor_version", withoutLogback
compile group: 'com.h2database', name: 'h2', version: '1.4.197'
}
//
// JaCoCo code coverage
//
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.4"
}
jacocoTestReport {
reports { jacoco ->
jacoco.xml.enabled = true
jacoco.html.enabled = true
}
}
test.finalizedBy(project.tasks.jacocoTestReport)
//
// Service manifest generation
//
sourceSets {
logger.info("${project.projectDir}/src/generated/kotlin")
generated {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
kotlin {
it.srcDir("${project.projectDir}/src/generated/kotlin")
}
resources {
it.srcDir("${project.projectDir}/src/generated/resources")
}
}
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
test {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
jar { from sourceSets.generated.output }
task cleanGenerated() {
File outputDir = file("src/generated")
outputDir.absolutePath
outputDir.deleteDir()
}
clean.dependsOn(cleanGenerated)
task generateBuildConfig() {
File outputDir = file("src/generated/kotlin")
if (!outputDir.exists()) outputDir.mkdirs()
String simpleName = project.name.replace("-service", "")
StringBuilder packageName = new StringBuilder()
simpleName.split("-").eachWithIndex { String entry, int i ->
if (i == 0) packageName.append(entry)
else {
packageName.append(".")
packageName.append(entry)
}
}
StringBuilder classNameBuilder = new StringBuilder()
simpleName.split("-").eachWithIndex { String entry, int i ->
classNameBuilder.append(entry.capitalize())
}
String fullPackageName = "${project.group}.${packageName.toString()}.api"
File packagePath = file("$outputDir/${fullPackageName.replace('.', '/')}")
if (!packagePath.exists()) packagePath.mkdirs()
String className = "${classNameBuilder.toString()}ServiceDescription"
File configFile = file("$packagePath/${className}.kt")
configFile.delete()
configFile << """
package $fullPackageName
import dk.sdu.cloud.ServiceDescription
object $className : ServiceDescription {
override val name: String = "${project.name.replace("-service", "")}"
override val version: String = "${project.version}"
}
""".stripIndent().trim()
}
compileKotlin.dependsOn(generateBuildConfig)
//
// Dokka
//
apply plugin: org.jetbrains.dokka.gradle.DokkaPlugin
dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
}
// Task creators and utilities are exported in sduCloud
ext.sduCloud = ([
createTasksForApiJar: { String name, List<String> dependencies ->
String nameWithDashes = name.replace('.', '-')
String createApiJarTaskName = "${nameWithDashes}ApiJar"
String publishApiJarTaskName = "${nameWithDashes}ApiJar"
def apiJarTask = tasks.create(createApiJarTaskName, Jar) { task ->
task.baseName = nameWithDashes + '-api'
task.from(sourceSets.main.output)
task.from(sourceSets.generated.output)
task.from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
task.include("**/dk/sdu/cloud/${name.replace('.', '/')}/api/**")
task.include("META-INF/**/${project.name}.kotlin_module")
task.includeEmptyDirs = false
task.with(jar)
}
PublishingExtension publishing = publishing
def publication = publishing.publications.create(publishApiJarTaskName, MavenPublication)
publication.groupId = "dk.sdu.cloud"
publication.artifactId = "$nameWithDashes-api"
publication.artifact(apiJarTask)
publication.pom.withXml {
def dependenciesNode = it.asNode().appendNode("dependencies")
for (dep in dependencies) {
def splitDependency = dep.split(":")
if (splitDependency.length != 3) throw new IllegalArgumentException("Bad dependency: $dep")
def depNode = dependenciesNode.appendNode("dependency")
depNode.appendNode("groupId", splitDependency[0])
depNode.appendNode("artifactId", splitDependency[1])
depNode.appendNode("version", splitDependency[2])
}
}
}
])
run {
classpath sourceSets.generated.output
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
}
}
test {
systemProperty("log4j2.configurationFactory", "dk.sdu.cloud.micro.Log4j2ConfigFactory")
systemProperty("java.io.tmpdir", System.getProperty("java.io.tmpdir"))
}