This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
152 lines (122 loc) · 4.53 KB
/
build.gradle.kts
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
import org.gradle.jvm.tasks.Jar
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.tasks.JacocoReport
val warrenVersion by project
val kaleVersion by project
val kotlinVersion by project
val projectTitle = "Warren"
buildscript {
val buildscriptKotlinVersion = "1.1.51"
repositories {
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$buildscriptKotlinVersion")
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
}
}
apply {
plugin("com.github.johnrengelman.shadow")
plugin("maven")
plugin("maven-publish")
plugin("jacoco")
}
plugins {
kotlin("jvm") version "1.1.51"
}
jacoco {
toolVersion = "0.7.9"
}
val jacocoTestReport = project.tasks.getByName("jacocoTestReport")
jacocoTestReport.doFirst {
(jacocoTestReport as JacocoReport).classDirectories = fileTree("build/classes/main").apply {
// Exclude well known data classes that should contain no logic
// Remember to change values in codecov.yml too
exclude("**/*Event.*")
exclude("**/*State.*")
exclude("**/*Configuration.*")
exclude("**/*Runner.*")
exclude("**/*Factory.*")
exclude("**/*Sleeper.*")
}
jacocoTestReport.reports.xml.isEnabled = true
jacocoTestReport.reports.html.isEnabled = true
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_7.toString()
targetCompatibility = JavaVersion.VERSION_1_7.toString()
}
repositories {
mavenCentral()
gradleScriptKotlin()
maven { setUrl("https://maven.ci.carrot.codes") }
}
dependencies {
compile(kotlinModule("stdlib", kotlinVersion as String))
compile("org.slf4j:slf4j-api:1.7.21")
compile("chat.willow.kale:Kale:$kaleVersion")
compile("com.squareup.okio:okio:1.11.0")
runtime("org.slf4j:slf4j-simple:1.7.21")
testCompile("junit:junit:4.12")
testCompile("org.mockito:mockito-core:2.2.9")
testCompile("com.nhaarman:mockito-kotlin:1.2.0")
}
test {
testLogging.setEvents(listOf("passed", "skipped", "failed", "standardError"))
}
val buildNumberAddition = if(project.hasProperty("BUILD_NUMBER")) { ".${project.property("BUILD_NUMBER")}" } else { "" }
val branchAddition = if(project.hasProperty("BRANCH")) {
val safeBranchName = project.property("BRANCH")
.toString()
.map { if(Character.isJavaIdentifierPart(it)) it else '_' }
.joinToString(separator = "")
when (safeBranchName) {
"develop" -> ""
else -> "-$safeBranchName"
}
} else {
""
}
version = "$warrenVersion$buildNumberAddition$branchAddition"
group = "chat.willow.warren"
project.setProperty("archivesBaseName", projectTitle)
shadowJar {
mergeServiceFiles()
relocate("kotlin", "chat.willow.warren.repack.kotlin")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
}
val sourcesTask = task<Jar>("sourcesJar") {
dependsOn("classes")
from(sourceSets("main").allSource)
classifier = "sources"
}
project.artifacts.add("archives", sourcesTask)
project.artifacts.add("archives", shadowJarTask())
configure<PublishingExtension> {
val deployUrl = if (project.hasProperty("DEPLOY_URL")) { project.property("DEPLOY_URL") } else { project.buildDir.absolutePath }
this.repositories.maven({ setUrl("$deployUrl") })
publications {
create<MavenPublication>("mavenJava") {
from(components.getByName("java"))
artifact(shadowJarTask())
artifact(sourcesTask)
artifactId = projectTitle
}
}
}
fun Project.jar(setup: Jar.() -> Unit) = (project.tasks.getByName("jar") as Jar).setup()
fun jacoco(setup: JacocoPluginExtension.() -> Unit) = the<JacocoPluginExtension>().setup()
fun shadowJar(setup: ShadowJar.() -> Unit) = shadowJarTask().setup()
fun Project.test(setup: Test.() -> Unit) = (project.tasks.getByName("test") as Test).setup()
fun Project.compileJava(setup: JavaCompile.() -> Unit) = (project.tasks.getByName("compileJava") as JavaCompile).setup()
fun shadowJarTask() = (project.tasks.findByName("shadowJar") as ShadowJar)
fun sourceSets(name: String) = (project.property("sourceSets") as SourceSetContainer).getByName(name)