-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
build.gradle.kts
111 lines (90 loc) · 3.42 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
import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
val kotlinVersion: String = libs.versions.kotlin.get()
val detektVersion: String = Versions.DETEKT
val kotlinCompilerChecksum: String by project
group = "io.github.detekt"
version = "$kotlinVersion-$detektVersion"
val detektPublication = "DetektPublication"
plugins {
id("module")
alias(libs.plugins.gradleVersions)
alias(libs.plugins.shadow)
alias(libs.plugins.download)
}
dependencies {
compileOnly(libs.kotlin.compiler)
implementation(projects.detektApi)
implementation(projects.detektTooling)
runtimeOnly(projects.detektCore)
runtimeOnly(projects.detektRules)
testImplementation(libs.assertj)
testImplementation(libs.kotlinCompileTesting)
testImplementation(libs.kotlin.compilerEmbeddable)
}
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
tasks.test {
// https://github.com/detekt/detekt/issues/5646
enabled = false
}
tasks.shadowJar.configure {
relocate("org.jetbrains.kotlin.com.intellij", "com.intellij")
mergeServiceFiles()
dependencies {
include(dependency("io.gitlab.arturbosch.detekt:.*"))
include(dependency("io.github.detekt:.*"))
include(dependency("org.snakeyaml:snakeyaml-engine"))
include(dependency("io.github.davidburstrom.contester:contester-breakpoint"))
}
}
val verifyKotlinCompilerDownload by tasks.registering(Verify::class) {
src(file("$rootDir/build/kotlinc/kotlin-compiler-$kotlinVersion.zip"))
algorithm("SHA-256")
checksum(kotlinCompilerChecksum)
outputs.upToDateWhen { true }
}
val downloadKotlinCompiler by tasks.registering(Download::class) {
src("https://github.com/JetBrains/kotlin/releases/download/v$kotlinVersion/kotlin-compiler-$kotlinVersion.zip")
dest(file("$rootDir/build/kotlinc/kotlin-compiler-$kotlinVersion.zip"))
overwrite(false)
finalizedBy(verifyKotlinCompilerDownload)
}
val unzipKotlinCompiler by tasks.registering(Copy::class) {
dependsOn(downloadKotlinCompiler)
from(zipTree(downloadKotlinCompiler.get().dest))
into(file("$rootDir/build/kotlinc/$kotlinVersion"))
}
val testPluginKotlinc by tasks.registering(Task::class) {
dependsOn(unzipKotlinCompiler, tasks.shadowJar)
val baseExecutablePath = "${unzipKotlinCompiler.get().destinationDir}/kotlinc/bin/kotlinc"
val pluginParameters = "plugin:detekt-compiler-plugin:debug=true"
val kotlincExecution = providers.exec {
workingDir = file("$buildDir/tmp/kotlinc")
workingDir.mkdirs()
args = listOf(
"$projectDir/src/test/resources/hello.kt",
"-Xplugin=${tasks.shadowJar.get().archiveFile.get().asFile.absolutePath}",
"-P",
)
if (org.apache.tools.ant.taskdefs.condition.Os.isFamily("windows")) {
executable = "$baseExecutablePath.bat"
args("\"$pluginParameters\"")
} else {
executable = baseExecutablePath
args(pluginParameters)
}
}
doLast {
if (!kotlincExecution.standardError.asText.get().contains("warning: magicNumber:")) {
throw GradleException(
"kotlinc run with compiler plugin did not find MagicNumber issue as expected"
)
}
}
}
tasks.check {
dependsOn(testPluginKotlinc)
}