-
Notifications
You must be signed in to change notification settings - Fork 6
/
kotlin-guiced.gradle.kts
221 lines (190 loc) · 7.12 KB
/
kotlin-guiced.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
219
220
221
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.api.tasks.wrapper.Wrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
setUrl("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${property("kotlin.version")}")
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4")
}
}
plugins {
`lifecycle-base`
jacoco
}
apply {
plugin("com.jfrog.bintray")
plugin("maven-publish")
}
val PUBLISHED_CONFIGURATION_NAME = "published"
allprojects {
version = "0.0.5"
group = "org.jlleitschuh.guice"
repositories {
mavenCentral()
}
}
val jacocoTestResultTaskName = "jacocoTestReport"
subprojects {
apply {
plugin("com.jfrog.bintray")
plugin("kotlin")
plugin("maven-publish")
plugin("java-library")
plugin("jacoco")
}
val publicationName = "publication-$name"
bintray {
user = properties["bintray.publish.user"].toString()
key = properties["bintray.publish.key"].toString()
setPublications(publicationName)
with(pkg) {
repo = "maven-artifacts"
name = "kotlin-guiced"
publish = true
setLicenses("MIT")
setLabels("guice", "kotlin", "dependency injection")
vcsUrl = "https://github.com/JLLeitschuh/kotlin-guiced.git"
githubRepo = "https://github.com/JLLeitschuh/kotlin-guiced"
}
}
dependencies {
"compile"(kotlin(module = "stdlib", version = property("kotlin.version") as String))
"compile"(kotlin(module = "reflect", version = property("kotlin.version") as String))
"testCompile"(junitJupiter("junit-jupiter-api"))
"testCompile"(junitJupiter("junit-jupiter-params"))
"testCompile"(group = "com.natpryce", name = "hamkrest", version = "1.5.0.0")
"testRuntime"(junitJupiter("junit-jupiter-engine"))
"testRuntime"(create(group = "org.junit.platform", name = "junit-platform-launcher", version = "1.3.1"))
}
tasks.withType<KotlinCompile>().configureEach {
// Kotlin incremental compilation is enabled by default
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xprogressive"
/*
* Enables strict null checking when calling java methods using jsr305 annotations.
* https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support
*/
freeCompilerArgs += "-Xjsr305=strict"
}
}
tasks.withType<Test>().configureEach {
extensions.configure(typeOf<JacocoTaskExtension>()) {
/*
* Fix for Jacoco breaking Build Cache support.
* https://github.com/gradle/gradle/issues/5269
*/
isAppend = false
}
useJUnitPlatform {
filter {
includeTestsMatching("*Test")
includeTestsMatching("*Tests")
includeTestsMatching("*Spec")
}
}
testLogging {
events(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.STARTED)
displayGranularity = 0
showExceptions = true
showCauses = true
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
reports.junitXml.destination = file("${rootProject.buildDir}/test-results/${project.name}")
}
tasks.withType<JacocoReport>().configureEach {
reports {
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
}
val sourceJarTask = task<Jar>("sourceJar") {
from(java.sourceSets["main"].allSource)
classifier = "sources"
}
afterEvaluate {
// This ensures that the entire project's configuration has been resolved before creating a publish artifact.
publishing {
publications {
create<MavenPublication>(publicationName) {
from(components["java"])
artifact(sourceJarTask)
}
}
}
}
}
val jacocoRootReport = tasks.register<JacocoReport>("jacocoRootReport") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Generates an HTML code coverage report for all sub-projects."
val jacocoReportTasks =
subprojects
.asSequence()
.filter {
// Filter out source sets that don't have tests in them
// Otherwise, Jacoco tries to generate coverage data for tests that don't exist
!it.java.sourceSets["test"].allSource.isEmpty
}
.map { it.tasks["jacocoTestReport"] as JacocoReport }
.toList()
dependsOn(jacocoReportTasks)
executionData.setFrom(Callable { jacocoReportTasks.map { it.executionData } })
subprojects.forEach { testedProject ->
val sourceSets = testedProject.java.sourceSets
val mainSourceSet = sourceSets["main"]
[email protected](mainSourceSet.allSource.sourceDirectories)
[email protected](mainSourceSet.output)
}
reports {
html.isEnabled = true
xml.isEnabled = true
csv.isEnabled = false
}
}
allprojects {
// Configures the Jacoco tool version to be the same for all projects that have it applied.
pluginManager.withPlugin("jacoco") {
// If this project has the plugin applied, configure the tool version.
jacoco {
toolVersion = "0.8.2"
}
}
}
configurations.create(PUBLISHED_CONFIGURATION_NAME)
tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure {
dependsOn(jacocoRootReport)
}
tasks.withType<Wrapper>().configureEach {
description = "Configure the version of gradle to download and use"
gradleVersion = "5.1"
distributionType = Wrapper.DistributionType.ALL
}
fun DependencyHandler.junitJupiter(name: String) =
create(group = "org.junit.jupiter", name = name, version = "5.3.1")
/**
* Retrieves or configures the [bintray][com.jfrog.bintray.gradle.BintrayExtension] project extension.
*/
fun Project.`bintray`(configure: com.jfrog.bintray.gradle.BintrayExtension.() -> Unit = {}) =
extensions.getByName<com.jfrog.bintray.gradle.BintrayExtension>("bintray").apply { configure() }
/**
* Retrieves or configures the [publishing][org.gradle.api.publish.PublishingExtension] project extension.
*/
fun Project.`publishing`(configure: org.gradle.api.publish.PublishingExtension.() -> Unit = {}) =
extensions.getByName<org.gradle.api.publish.PublishingExtension>("publishing").apply { configure() }
/**
* Retrieves the [java][org.gradle.api.plugins.JavaPluginConvention] project convention.
*/
val Project.`java`: org.gradle.api.plugins.JavaPluginConvention
get() = convention.getPluginByName("java")