kotlin-gradle-plugin-idea: Replace special -for-compatibility-tests publication

... with separate module intended to download and prepare
the `kotlin-gradle-plugin-idea` classpath used for testing
backwards compatibility.
This commit is contained in:
sebastian.sellmair
2022-03-22 11:24:27 +01:00
parent 42ed0c5fe6
commit 310ab12a92
5 changed files with 59 additions and 61 deletions
-1
View File
@@ -20,7 +20,6 @@
<trust group="org.jetbrains.kotlin" name="kotlin-gradle-plugin-api"/>
<trust group="org.jetbrains.kotlin" name="kotlin-gradle-plugin-model"/>
<trust group="org.jetbrains.kotlin" name="kotlin-gradle-plugin-idea"/>
<trust group="org.jetbrains.kotlin" name="kotlin-gradle-plugin-idea-for-compatibility-tests"/>
<trust group="org.jetbrains.kotlin" name="kotlin-klib-commonizer-api"/>
<trust group="org.jetbrains.kotlin" name="kotlin-klib-commonizer-embeddable"/>
<trust group="org.jetbrains.kotlin" name="kotlin-tooling-metadata"/>
@@ -0,0 +1,47 @@
@file:Suppress("HasPlatformType")
/**
* Version of kotlin-gradle-plugin-idea module that should be resolved for compatibility tests
* This version can be treated as 'minimal guaranteed backwards compatible version' of the module.
*/
val testedVersion = "1.7.0-dev-2723"
//region Download and prepare classpath for specified tested version
val classpathDestination = layout.buildDirectory.dir("classpath")
val incomingClasspath by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
dependencies {
incomingClasspath(kotlin("gradle-plugin-idea", testedVersion))
}
val syncClasspath by tasks.register<Sync>("syncClasspath") {
from(incomingClasspath)
into(classpathDestination)
/* Test if the correct version was resolved */
doLast {
val expectedJar = destinationDir.resolve("kotlin-gradle-plugin-idea-$testedVersion.jar")
check(expectedJar.exists()) { "Expected $expectedJar in classpath. Found ${destinationDir.listFiles().orEmpty()}" }
}
}
val outgoingClasspath by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
outgoing.artifact(classpathDestination) { builtBy(syncClasspath) }
}
tasks.register<Delete>("clean") {
delete(project.buildDir)
}
//endregion
@@ -4,10 +4,6 @@ plugins {
`maven-publish`
}
object BackwardsCompatibilityTestConfiguration {
const val minimalBackwardsCompatibleVersion = "1.7.0-dev-2723"
}
kotlin.sourceSets.configureEach {
languageSettings.apiVersion = "1.4"
languageSettings.languageVersion = "1.4"
@@ -36,69 +32,22 @@ sourcesJar()
//region Setup: Backwards compatibility tests
/*
A special publication is necessary for later downloading such artifact from within this module.
If we wanted to download a publication with the same coordinates, Gradle would always rewrite
the dependency to a local project dependency (knowing, that the coodriantes belong to this project)
*/
publishing {
publications.create<MavenPublication>("for-compatibility-tests") {
artifactId = "kotlin-gradle-plugin-idea-for-compatibility-tests"
artifact(tasks.named("jar"))
}
}
/* Setup Backwards Compatibility Test */
run {
/* When -Pkgp-idea-snapshot is set, then the test runs against a locally installed snapshot version (./gradlew install) */
val isSnapshotTest = project.providers.gradleProperty("kotlin-gradle-plugin-idea.snapshot").isPresent
repositories {
if (isSnapshotTest) mavenLocal()
}
val version = if (isSnapshotTest) properties["defaultSnapshotVersion"].toString()
else BackwardsCompatibilityTestConfiguration.minimalBackwardsCompatibleVersion
val minimalBackwardsCompatibleVersionTestClasspath by configurations.creating {
val compatibilityTestClasspath by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
dependencies {
minimalBackwardsCompatibleVersionTestClasspath(
"org.jetbrains.kotlin:kotlin-gradle-plugin-idea-for-compatibility-tests:$version"
)
minimalBackwardsCompatibleVersionTestClasspath(
"org.jetbrains.kotlin:kotlin-stdlib:$version"
)
compatibilityTestClasspath(project(":kotlin-gradle-plugin-idea-for-compatibility-tests"))
}
tasks.test {
dependsOnKotlinGradlePluginInstall()
inputs.files(minimalBackwardsCompatibleVersionTestClasspath)
doFirst {
if (isSnapshotTest) logger.quiet("Running test against snapshot: $version")
else logger.quiet("Running test against $version")
/*
Perform a check on the resolved classpath to ensure, that indeed the requested version is resolved.
This is a last line of defense against some unexpected Gradle resolution (like back resolving to this original project)
*/
val resolvedClasspath = minimalBackwardsCompatibleVersionTestClasspath.files
if (resolvedClasspath.none { "kotlin-gradle-plugin-idea-for-compatibility-tests-$version.jar" in it.path }) {
throw IllegalStateException(buildString {
appendLine("Bad backwardsCompatibilityClasspath: $resolvedClasspath")
appendLine("Dependencies:${minimalBackwardsCompatibleVersionTestClasspath.allDependencies.joinToString()}")
})
}
systemProperty(
"backwardsCompatibilityClasspath",
resolvedClasspath.joinToString(";") { it.absolutePath }
)
}
inputs.files(compatibilityTestClasspath)
doFirst { systemProperty("compatibilityTestClasspath", compatibilityTestClasspath.files.joinToString(";") { it.absolutePath }) }
}
}
@@ -122,11 +122,12 @@ private fun getClassLoaderForBackwardsCompatibilityTest(): ClassLoader {
}
private fun getClasspathForBackwardsCompatibilityTest(): List<File> {
val backwardsCompatibilityClasspathString = System.getProperty("backwardsCompatibilityClasspath")
?: error("Missing backwardsCompatibilityClasspath system property")
val compatibilityTestClasspath = System.getProperty("compatibilityTestClasspath")
?: error("Missing compatibilityTestClasspath system property")
return backwardsCompatibilityClasspathString.split(";").map { path -> File(path) }
return compatibilityTestClasspath.split(";").map { path -> File(path) }
.onEach { file -> if (!file.exists()) println("[WARNING] Missing $file") }
.flatMap { file -> if(file.isDirectory) file.listFiles().orEmpty().toList() else listOf(file) }
}
private fun deserializeModelWithBackwardsCompatibleClasses(model: IdeaKotlinProjectModel): Any {
+2
View File
@@ -223,6 +223,7 @@ include ":benchmarks",
":kotlin-project-model",
":kotlin-gradle-plugin-api",
":kotlin-gradle-plugin-idea",
":kotlin-gradle-plugin-idea-for-compatibility-tests",
":kotlin-gradle-plugin-dsl-codegen",
":kotlin-gradle-plugin-npm-versions-codegen",
":kotlin-gradle-statistics",
@@ -669,6 +670,7 @@ project(':tools:kotlinp').projectDir = "$rootDir/libraries/tools/kotlinp" as Fil
project(':kotlin-project-model').projectDir = "$rootDir/libraries/tools/kotlin-project-model" as File
project(':kotlin-gradle-plugin-api').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-api" as File
project(':kotlin-gradle-plugin-idea').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea" as File
project(':kotlin-gradle-plugin-idea-for-compatibility-tests').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea-for-compatibility-tests" as File
project(':kotlin-gradle-plugin-dsl-codegen').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-dsl-codegen" as File
project(':kotlin-gradle-plugin-npm-versions-codegen').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-npm-versions-codegen" as File
project(':kotlin-gradle-statistics').projectDir = "$rootDir/libraries/tools/kotlin-gradle-statistics" as File