-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
218 lines (183 loc) · 8.32 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
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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.72"
id("org.sonarqube") version "2.8"
jacoco
}
val skipJacoco = setOf(":api")
allprojects {
group = "br.com.gamemods"
version = "0.1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
}
afterEvaluate {
if (!plugins.hasPlugin("kotlin")) {
return@afterEvaluate
}
if (!plugins.hasPlugin("org.sonarqube")) {
apply(plugin = "org.sonarqube")
}
val skipJacoco = path.startsWith(":api:jigsaw") || path in skipJacoco
if (!skipJacoco && !plugins.hasPlugin("jacoco")) {
apply(plugin = "jacoco")
}
sonarqube {
properties {
property("sonar.sources", "src/main")
property("sonar.tests", "src/test")
if (this != rootProject) {
property(
"sonar.coverage.jacoco.xmlReportPaths",
"$buildDir/reports/jacoco/test/jacocoTestReport.xml".replace('/', '\\')
)
}
}
}
val moduleName = "br.com.gamemods.litecraft"+path.replace(':', '.').replace('-','.')
tasks.withType<JavaCompile>().configureEach {
options.javaModuleVersion.set(provider { project.version as String })
// this is needed because we have a separate compile step in this example with the 'module-info.java' is in 'main/java' and the Kotlin code is in 'main/kotlin'
//options.compilerArgs = listOf("--patch-module", "$moduleName=${sourceSets.main.get().output.asPath}")
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "13"
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.contracts.ExperimentalContracts"
}
tasks.named<JavaCompile>("compileJava") {
dependsOn(":compileKotlin")
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = options.compilerArgs + listOf(
// include Gradle dependencies as modules
"--module-path", sourceSets["main"].compileClasspath.asPath,
"--patch-module", "$moduleName=${sourceSets.main.get().output.asPath}"
)
sourceSets["main"].compileClasspath = files()
}
}
sourceSets.main.configure {
//java.setSrcDirs(listOf("src/main/kotlin"))
}
plugins.withType<JavaPlugin>().configureEach {
configure<JavaPluginExtension> {
modularity.inferModulePath.set(true)
}
}
dependencies {
api(kotlin("stdlib-jdk8", embeddedKotlinVersion))
api(kotlin("reflect", embeddedKotlinVersion))
testImplementation(kotlin("test-junit5", embeddedKotlinVersion))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0-M1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0-M1")
testImplementation("org.mockito:mockito-junit-jupiter:3.3.3")
testImplementation("org.mockito:mockito-inline:3.3.3")
testImplementation("com.nhaarman:mockito-kotlin:1.6.0")
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("com.natpryce:hamkrest:1.7.0.3")
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging {
events("PASSED", "FAILED", "SKIPPED", "STANDARD_OUT", "STANDARD_ERROR")
}
}
if (plugins.hasPlugin("jacoco")) {
jacoco {
//toolVersion = jacocoVersion
reportsDir = file("$buildDir/reports/jacoco")
}
tasks {
named<JacocoReport>("jacocoTestReport") {
dependsOn("test")
classDirectories.setFrom(files("${buildDir}/classes"))
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
}
}
}
}
listOf(project(":api:jigsaw"), project(":api:jigsaw")).forEach {
it.sonarqube {
isSkipProject = true
}
}
sonarqube {
properties {
property("sonar.scm.provider", "git")
//property("sonar.jacoco.reportPaths", allTestCoverageFile)
property("sonar.host.url", project.findProperty("litecraft.sonar.host.url") ?: System.getenv("litecraft_sonar_host_url"))
property("sonar.login", project.findProperty("litecraft.sonar.login.token")?.takeUnless { it.toString().startsWith("<secret") } ?: System.getenv("litecraft_sonar_login_token")?.takeIf { it.isNotBlank() } ?: System.getenv("SONAR_TOKEN"))
property("sonar.organization", project.findProperty("litecraft.sonar.organization") ?: System.getenv("litecraft_sonar_organization"))
property("sonar.projectKey",project.findProperty("litecraft.sonar.projectKey") ?: System.getenv("litecraft_sonar_projectKey"))
property("sonar.projectName", project.findProperty("litecraft.sonar.projectName") ?: System.getenv("litecraft_sonar_projectName"))
property("sonar.rootModuleName", project.findProperty("litecraft.sonar.rootModuleName") ?: System.getenv("litecraft_sonar_rootModuleName"))
property("sonar.cpd.cross_project", true)
property("sonar.java.source", "14")
//property("sonar.java.binaries", "build/libs/xyz-0.0.1-SNAPSHOT.jar")
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.sources", "src/main")
property("sonar.tests", "src/test")
//property("sonar.java.test.binaries", "build/classes/java/test")
property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/codeCoverageReport.xml")
}
}
sourceSets {
main {
java.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}
test {
java.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}
}
kotlin.sourceSets {
main { kotlin.setSrcDirs(emptyList<String>()) }
test { kotlin.setSrcDirs(emptyList<String>()) }
}
// task to gather code coverage from multiple subprojects
// NOTE: the `JacocoReport` tasks do *not* depend on the `test` task by default. Meaning you have to ensure
// that `test` (or other tasks generating code coverage) run before generating the report.
// You can achieve this by calling the `test` lifecycle task manually
// $ ./gradlew test codeCoverageReport
tasks.register<JacocoReport>("codeCoverageReport") {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
subprojects {
if (path != ":api" && !path.startsWith(":api:jigsaw")) {
dependsOn("$path:jacocoTestReport")
}
val subproject = this
subproject.plugins.withType<JacocoPlugin>().configureEach {
subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.configureEach {
val testTask = this
sourceSets(subproject.sourceSets.main.get())
executionData(testTask)
}
// To automatically run `test` every time `./gradlew codeCoverageReport` is called,
// you may want to set up a task dependency between them as shown below.
// Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
// may have a negative effect on the configuration time of your build.
//subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.forEach {
// rootProject.tasks["codeCoverageReport"].dependsOn(it)
//}
}
}
// enable the different report types (html, xml, csv)
reports {
// xml is usually used to integrate code coverage with
// other tools like SonarQube, Coveralls or Codecov
xml.isEnabled = true
// HTML reports can be used to see code coverage
// without any external tools
html.isEnabled = true
}
}
tasks.named("sonarqube") {
dependsOn("codeCoverageReport")
}