forked from detekt/detekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
307 lines (263 loc) · 9.8 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.jfrog.bintray.gradle.BintrayExtension
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.util.GFileUtils
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.Date
plugins {
kotlin("jvm") version "1.3.21"
id("com.jfrog.bintray") version "1.8.4"
id("com.github.ben-manes.versions") version "0.20.0"
id("com.github.johnrengelman.shadow") version "4.0.3" apply false
id("org.sonarqube") version "2.6.2"
id("io.gitlab.arturbosch.detekt")
id("org.jetbrains.dokka") version "0.9.17"
jacoco
}
tasks.withType<Wrapper> {
gradleVersion = "5.2"
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.
*/
val gradlePluginWrapperDir = File(gradle.includedBuild("detekt-gradle-plugin").projectDir, "/gradle/wrapper")
GFileUtils.mkdirs(gradlePluginWrapperDir)
copy {
from(propertiesFile)
into(gradlePluginWrapperDir)
}
}
}
tasks.withType<Test> {
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":test"))
}
tasks.withType<Detekt> {
dependsOn("detekt-cli:assemble")
dependsOn("detekt-formatting:assemble")
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":detekt"))
}
val detektVersion: String by project
val usedDetektVersion: String by project
allprojects {
group = "io.gitlab.arturbosch.detekt"
version = detektVersion
repositories {
mavenLocal()
jcenter()
maven(url = "https://dl.bintray.com/arturbosch/generic")
}
}
subprojects {
val project = this
apply {
plugin("java-library")
plugin("kotlin")
plugin("com.jfrog.bintray")
plugin("maven-publish")
plugin("io.gitlab.arturbosch.detekt")
plugin("org.jetbrains.dokka")
plugin("jacoco")
}
val jacocoVersion: String by project
jacoco.toolVersion = jacocoVersion
tasks.named<JacocoReport>("jacocoTestReport").configure {
reports.xml.isEnabled = true
reports.html.isEnabled = true
dependsOn(tasks.named("test"))
}
val userHome = System.getProperty("user.home")
detekt {
debug = true
toolVersion = usedDetektVersion
config = files(
project.rootDir.resolve("detekt-cli/src/main/resources/default-detekt-config.yml"),
project.rootDir.resolve("reports/failfast.yml")
)
filters = ".*/resources/.*,.*/build/.*"
baseline = project.rootDir.resolve("reports/baseline.xml")
reports {
xml.enabled = true
html.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-watcher", "detekt-generator")
if (project.name in shadowedProjects) {
apply {
plugin("application")
plugin("com.github.johnrengelman.shadow")
tasks.withType<ShadowJar> {
archiveClassifier.set("all")
}
}
}
tasks.withType<Test> {
useJUnitPlatform()
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> {
kotlinOptions.jvmTarget = "1.8"
// https://youtrack.jetbrains.com/issue/KT-24946
kotlinOptions.freeCompilerArgs = listOf(
"-Xskip-runtime-version-check",
"-Xdisable-default-scripting-plugin",
"-Xuse-experimental=kotlin.Experimental"
)
kotlinOptions.allWarningsAsErrors = shouldTreatCompilerWarningsAsErrors()
}
bintray {
user = System.getenv("BINTRAY_USER") ?: ""
key = System.getenv("BINTRAY_API_KEY") ?: ""
val mavenCentralUser = System.getenv("MAVEN_CENTRAL_USER") ?: ""
val mavenCentralPassword = System.getenv("MAVEN_CENTRAL_PW") ?: ""
setPublications("DetektPublication")
override = (project.version as? String)?.endsWith("-SNAPSHOT") == true
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"
})
})
})
}
tasks.withType<DokkaTask> {
// suppresses undocumented classes but not dokka warnings
// https://github.com/Kotlin/dokka/issues/229 && https://github.com/Kotlin/dokka/issues/319
reportUndocumented = false
outputFormat = "javadoc"
outputDirectory = "$buildDir/javadoc"
// Java 8 is only version supported both by Oracle/OpenJDK and Dokka itself
// https://github.com/Kotlin/dokka/issues/294
enabled = JavaVersion.current().isJava8
}
val sourcesJar by tasks.creating(Jar::class) {
dependsOn("classes")
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadocJar by tasks.creating(Jar::class) {
dependsOn("dokka")
archiveClassifier.set("javadoc")
from(buildDir.resolve("javadoc"))
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
}
configure<PublishingExtension> {
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.withXml {
asNode().apply {
appendNode("description", "Static code analysis for Kotlin")
appendNode("name", "detekt")
appendNode("url", "https://arturbosch.github.io/detekt")
val license = appendNode("licenses").appendNode("license")
license.appendNode("name", "The Apache Software License, Version 2.0")
license.appendNode("url", "http://www.apache.org/licenses/LICENSE-2.0.txt")
license.appendNode("distribution", "repo")
val developer = appendNode("developers").appendNode("developer")
developer.appendNode("id", "Artur Bosch")
developer.appendNode("name", "Artur Bosch")
developer.appendNode("email", "[email protected]")
appendNode("scm").appendNode("url", "https://github.com/arturbosch/detekt")
}
}
}
}
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"].java.srcDirs("src/main/kotlin")
}
/**
* Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
*/
fun shouldTreatCompilerWarningsAsErrors(): Boolean {
return project.findProperty("warningsAsErrors") == "true"
}
dependencies {
detektPlugins(project(":detekt-formatting"))
}
val detektFormat by tasks.registering(Detekt::class) {
description = "Reformats whole code base."
input = files(projectDir)
filters.set(".*/resources/.*")
config = files(
projectDir.resolve("detekt-cli/src/main/resources/default-detekt-config.yml"),
projectDir.resolve("reports/format.yml")
)
debug = true
parallel = true
disableDefaultRuleSets = true
reports {
xml { enabled = false }
html { enabled = false }
}
}
val detektAll by tasks.registering(Detekt::class) {
debug = true
parallel = true
input = files(projectDir)
config = files(
project.rootDir.resolve("detekt-cli/src/main/resources/default-detekt-config.yml"),
project.rootDir.resolve("reports/failfast.yml")
)
filters.set(".*/resources/.*,.*/build/.*")
baseline.set(project.rootDir.resolve("reports/baseline.xml"))
reports {
xml.enabled = false
html.enabled = false
}
}