-
Notifications
You must be signed in to change notification settings - Fork 55
/
build.gradle.kts
168 lines (141 loc) · 6.16 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
import com.gradle.publish.*
import kotlinx.validation.build.*
import org.jetbrains.kotlin.gradle.tasks.*
plugins {
kotlin("jvm")
`java-gradle-plugin`
id("com.gradle.plugin-publish") apply false
signing
`maven-publish`
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
sourceSets {
test {
java.srcDir("src/test/kotlin")
}
}
sourceSets {
create("functionalTest") {
withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class) {
}
compileClasspath += sourceSets.main.get().output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}
tasks.register<Test>("functionalTest") {
testClassesDirs = sourceSets["functionalTest"].output.classesDirs
classpath = sourceSets["functionalTest"].runtimeClasspath
}
tasks.check { dependsOn(tasks["functionalTest"]) }
// While gradle testkit supports injection of the plugin classpath it doesn't allow using dependency notation
// to determine the actual runtime classpath for the plugin. It uses isolation, so plugins applied by the build
// script are not visible in the plugin classloader. This means optional dependencies (dependent on applied plugins -
// for example kotlin multiplatform) are not visible even if they are in regular gradle use. This hack will allow
// extending the classpath. It is based upon: https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection
// Create a configuration to register the dependencies against
val testPluginRuntimeConfiguration = configurations.register("testPluginRuntime")
// The task that will create a file that stores the classpath needed for the plugin to have additional runtime dependencies
// This file is then used in to tell TestKit which classpath to use.
val createClasspathManifest = tasks.register("createClasspathManifest") {
val outputDir = buildDir.resolve("cpManifests")
inputs.files(testPluginRuntimeConfiguration)
.withPropertyName("runtimeClasspath")
.withNormalizer(ClasspathNormalizer::class)
outputs.dir(outputDir)
.withPropertyName("outputDir")
doLast {
outputDir.mkdirs()
file(outputDir.resolve("plugin-classpath.txt")).writeText(testPluginRuntimeConfiguration.get().joinToString("\n"))
}
}
val kotlinVersion: String by project
val androidGradlePluginVersion: String = "7.2.2"
configurations.implementation {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}
dependencies {
implementation(gradleApi())
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0")
implementation("org.ow2.asm:asm:9.2")
implementation("org.ow2.asm:asm-tree:9.2")
implementation("com.googlecode.java-diff-utils:diffutils:1.3.0")
compileOnly("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:1.6.0")
compileOnly("com.android.tools.build:gradle:${androidGradlePluginVersion}")
// The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
// unlike the regular way gradle loads plugins.
add(testPluginRuntimeConfiguration.name, "org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:$kotlinVersion")
add(testPluginRuntimeConfiguration.name, "com.android.tools.build:gradle:${androidGradlePluginVersion}")
testImplementation(kotlin("test-junit"))
"functionalTestImplementation"(files(createClasspathManifest))
"functionalTestImplementation"("org.assertj:assertj-core:3.18.1")
"functionalTestImplementation"(gradleTestKit())
"functionalTestImplementation"(kotlin("test-junit"))
}
tasks.compileKotlin {
kotlinOptions.apply {
languageVersion = "1.4"
apiVersion = "1.4"
jvmTarget = "1.8"
// TODO revert that when updating Kotlin. This flag also affects kts files and prevents
// the project from build due to "w: Language version 1.4 is deprecated and its support will be removed"
// allWarningsAsErrors = true
// Suppress the warning about kotlin-reflect 1.3 and kotlin-stdlib 1.4 in the classpath.
// It's incorrect in this case because we're limiting API version to 1.3 anyway.
freeCompilerArgs += "-Xskip-runtime-version-check"
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks {
compileTestKotlin {
kotlinOptions {
languageVersion = "1.6"
}
}
test {
systemProperty("overwrite.output", System.getProperty("overwrite.output", "false"))
systemProperty("testCasesClassesDirs", sourceSets.test.get().output.classesDirs.asPath)
jvmArgs("-ea")
}
}
properties["DeployVersion"]?.let { version = it }
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
mavenCentralMetadata()
mavenCentralArtifacts(project, project.sourceSets.main.get().allSource)
}
mavenRepositoryPublishing(project)
mavenCentralMetadata()
}
publications.withType(MavenPublication::class).all {
signPublicationIfKeyPresent(this)
}
}
apply(plugin = "org.gradle.java-gradle-plugin")
apply(plugin = "com.gradle.plugin-publish")
extensions.getByType(PluginBundleExtension::class).apply {
website = "https://github.com/Kotlin/binary-compatibility-validator"
vcsUrl = "https://github.com/Kotlin/binary-compatibility-validator"
tags = listOf("kotlin", "api-management", "binary-compatibility")
}
gradlePlugin {
testSourceSets(sourceSets["functionalTest"])
plugins {
create("binary-compatibility-validator") {
id = "org.jetbrains.kotlinx.binary-compatibility-validator"
implementationClass = "kotlinx.validation.BinaryCompatibilityValidatorPlugin"
displayName = "Binary compatibility validator"
description = "Produces binary API dumps and compares them in order to verify that binary API is preserved"
}
}
}