[KPM] kotlin-gradle-plugin-idea: Use special publication for backwards compatibility tests

KT-51386
This commit is contained in:
sebastian.sellmair
2022-03-07 12:05:23 +01:00
committed by Space
parent 555db121fa
commit a4eb62e317
2 changed files with 35 additions and 5 deletions
+1
View File
@@ -20,6 +20,7 @@
<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"/>
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm")
`java-test-fixtures`
`maven-publish`
}
object BackwardsCompatibilityTestConfiguration {
@@ -29,10 +30,28 @@ dependencies {
testFixturesImplementation(project(":kotlin-test:kotlin-test-junit"))
}
repositories {
mavenLocal()
}
publish()
javadocJar()
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) */
@@ -48,23 +67,31 @@ run {
val minimalBackwardsCompatibleVersionTestClasspath by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
}
}
dependencies {
minimalBackwardsCompatibleVersionTestClasspath("org.jetbrains.kotlin:kotlin-gradle-plugin-idea:$version")
minimalBackwardsCompatibleVersionTestClasspath(
"org.jetbrains.kotlin:kotlin-gradle-plugin-idea-for-compatibility-tests:$version"
)
minimalBackwardsCompatibleVersionTestClasspath(
"org.jetbrains.kotlin:kotlin-stdlib:$version"
)
}
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-$version.jar" in it.path }) {
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()}")
@@ -78,3 +105,5 @@ run {
}
}
}
//endregion