forked from detekt/detekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
347 lines (301 loc) · 10.7 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import com.jfrog.bintray.gradle.BintrayExtension
import groovy.lang.GroovyObject
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import java.util.Date
plugins {
id("io.gitlab.arturbosch.detekt")
jacoco
`maven-publish`
// Plugin versions for these plugins are defined in gradle.properties and applied in settings.gradle.kts
id("com.jfrog.artifactory") apply false
id("com.jfrog.bintray")
id("org.jetbrains.dokka") apply false
id("com.github.ben-manes.versions")
kotlin("jvm")
id("com.github.johnrengelman.shadow") apply false
id("org.sonarqube")
}
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
tasks.wrapper {
val gradleVersion: String by project
this.gradleVersion = gradleVersion
distributionType = Wrapper.DistributionType.ALL
doLast {
/*
* Copy the properties file into the detekt-gradle-plugin project.
* This allows IDEs like IntelliJ to import the detekt-gradle-plugin as a standalone project.
*/
copy {
from(propertiesFile)
into(file("${gradle.includedBuild("detekt-gradle-plugin").projectDir}/gradle/wrapper"))
}
}
}
tasks.check {
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":check"))
}
tasks.withType<Detekt>().configureEach {
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":detekt"))
}
val jacocoVersion: String by project
jacoco.toolVersion = jacocoVersion
tasks {
jacocoTestReport {
executionData.setFrom(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))
subprojects
.filterNot { it.name in listOf("detekt-test", "detekt-sample-extensions") }
.forEach {
[email protected](it.sourceSets.main.get())
[email protected](it.tasks.test)
}
reports {
xml.isEnabled = true
xml.destination = file("$buildDir/reports/jacoco/report.xml")
}
}
}
val detektVersion: String by project
allprojects {
group = "io.gitlab.arturbosch.detekt"
version = detektVersion + if (System.getProperty("snapshot")?.toBoolean() == true) "-SNAPSHOT" else ""
repositories {
jcenter()
}
}
subprojects {
val project = this
apply {
plugin("java-library")
plugin("kotlin")
plugin("com.jfrog.bintray")
plugin("com.jfrog.artifactory")
plugin("maven-publish")
plugin("io.gitlab.arturbosch.detekt")
}
if (project.name !in listOf("detekt-test", "detekt-sample-extensions")) {
apply {
plugin("jacoco")
}
jacoco.toolVersion = jacocoVersion
}
tasks.withType<Detekt>().configureEach {
exclude("resources/")
exclude("build/")
jvmTarget = "1.8"
}
val userHome = System.getProperty("user.home")
detekt {
buildUponDefaultConfig = true
baseline = file("$rootDir/config/detekt/baseline.xml")
reports {
xml.enabled = true
html.enabled = true
txt.enabled = true
}
idea {
path = "$userHome/.idea"
codeStyleScheme = "$userHome/.idea/idea-code-style.xml"
inspectionsProfile = "$userHome/.idea/inspect.xml"
report = "project.projectDir/reports"
mask = "*.kt"
}
}
val shadowedProjects = listOf("detekt-cli", "detekt-generator")
if (project.name in shadowedProjects) {
apply {
plugin("application")
plugin("com.github.johnrengelman.shadow")
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
systemProperty("SPEK_TIMEOUT", 0) // disable test timeout
val compileSnippetText: Boolean = if (project.hasProperty("compile-test-snippets")) {
(project.property("compile-test-snippets") as String).toBoolean()
} else {
false
}
systemProperty("compile-snippet-tests", compileSnippetText)
testLogging {
// set options for log level LIFECYCLE
events = setOf(
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
)
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
// https://youtrack.jetbrains.com/issue/KT-24946
kotlinOptions.freeCompilerArgs = listOf(
"-progressive",
"-Xskip-runtime-version-check",
"-Xdisable-default-scripting-plugin",
"-Xuse-experimental=kotlin.Experimental"
)
kotlinOptions.allWarningsAsErrors = shouldTreatCompilerWarningsAsErrors()
}
val bintrayUser = findProperty("bintrayUser")?.toString() ?: System.getenv("BINTRAY_USER")
val bintrayKey = findProperty("bintrayKey")?.toString() ?: System.getenv("BINTRAY_API_KEY")
val detektPublication = "DetektPublication"
bintray {
user = bintrayUser
key = bintrayKey
val mavenCentralUser = System.getenv("MAVEN_CENTRAL_USER") ?: ""
val mavenCentralPassword = System.getenv("MAVEN_CENTRAL_PW") ?: ""
setPublications(detektPublication)
pkg(delegateClosureOf<BintrayExtension.PackageConfig> {
repo = "code-analysis"
name = "detekt"
userOrg = "arturbosch"
setLicenses("Apache-2.0")
vcsUrl = "https://github.com/arturbosch/detekt"
version(delegateClosureOf<BintrayExtension.VersionConfig> {
name = project.version as? String
released = Date().toString()
gpg(delegateClosureOf<BintrayExtension.GpgConfig> {
sign = true
})
mavenCentralSync(delegateClosureOf<BintrayExtension.MavenCentralSyncConfig> {
sync = true
user = mavenCentralUser
password = mavenCentralPassword
close = "1"
})
})
})
}
val sourcesJar by tasks.creating(Jar::class) {
dependsOn(tasks.classes)
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val javadocJar by tasks.creating(Jar::class) {
from(tasks.javadoc)
archiveClassifier.set("javadoc")
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
}
publishing {
publications.create<MavenPublication>(detektPublication) {
from(components["java"])
artifact(sourcesJar)
artifact(javadocJar)
if (project.name == "detekt-cli") {
artifact(tasks.getByName("shadowJar"))
}
groupId = [email protected] as? String
artifactId = [email protected]
version = [email protected] as? String
pom {
description.set("Static code analysis for Kotlin")
name.set("detekt")
url.set("https://arturbosch.github.io/detekt")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("Artur Bosch")
name.set("Artur Bosch")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/arturbosch/detekt")
}
}
}
}
configure<ArtifactoryPluginConvention> {
setContextUrl("https://oss.jfrog.org/artifactory")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "oss-snapshot-local")
setProperty("username", bintrayUser)
setProperty("password", bintrayKey)
setProperty("maven", true)
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", detektPublication)
setProperty("publishArtifacts", true)
setProperty("publishPom", true)
})
})
}
val assertjVersion: String by project
val spekVersion: String by project
val kotlinTest by configurations.creating
dependencies {
implementation(kotlin("stdlib"))
detekt(project(":detekt-cli"))
detektPlugins(project(":detekt-formatting"))
kotlinTest("org.assertj:assertj-core:$assertjVersion")
kotlinTest("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
}
sourceSets.main.get().java.srcDirs("src/main/kotlin")
}
/**
* Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
*/
fun shouldTreatCompilerWarningsAsErrors(): Boolean {
return project.findProperty("warningsAsErrors") == "true"
}
dependencies {
detekt(project(":detekt-cli"))
detektPlugins(project(":detekt-formatting"))
}
val detektFormat by tasks.registering(Detekt::class) {
description = "Reformats whole code base."
parallel = true
disableDefaultRuleSets = true
buildUponDefaultConfig = true
autoCorrect = true
setSource(files(projectDir))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
config.setFrom(files("$rootDir/config/detekt/format.yml"))
reports {
xml.enabled = false
html.enabled = false
txt.enabled = false
}
}
val detektAll by tasks.registering(Detekt::class) {
description = "Runs over whole code base without the starting overhead for each module."
parallel = true
buildUponDefaultConfig = true
setSource(files(projectDir))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
baseline.set(file("$rootDir/config/detekt/baseline.xml"))
reports {
xml.enabled = false
html.enabled = false
txt.enabled = false
}
}