diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 8233534b507..d49b4c45335 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -20,7 +20,6 @@ - diff --git a/libraries/tools/kotlin-gradle-plugin-idea-for-compatibility-tests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-idea-for-compatibility-tests/build.gradle.kts new file mode 100644 index 00000000000..0cbcd019413 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-idea-for-compatibility-tests/build.gradle.kts @@ -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("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("clean") { + delete(project.buildDir) +} + +//endregion diff --git a/libraries/tools/kotlin-gradle-plugin-idea/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-idea/build.gradle.kts index 38dc4879496..1fc57f8bc88 100644 --- a/libraries/tools/kotlin-gradle-plugin-idea/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-idea/build.gradle.kts @@ -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("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 }) } } } diff --git a/libraries/tools/kotlin-gradle-plugin-idea/src/test/kotlin/org/jetbrains/kotlin/gradle/kpm/idea/BackwardsCompatibilityDeserializationTest.kt b/libraries/tools/kotlin-gradle-plugin-idea/src/test/kotlin/org/jetbrains/kotlin/gradle/kpm/idea/BackwardsCompatibilityDeserializationTest.kt index fd68c31338e..c9a3497fdd9 100644 --- a/libraries/tools/kotlin-gradle-plugin-idea/src/test/kotlin/org/jetbrains/kotlin/gradle/kpm/idea/BackwardsCompatibilityDeserializationTest.kt +++ b/libraries/tools/kotlin-gradle-plugin-idea/src/test/kotlin/org/jetbrains/kotlin/gradle/kpm/idea/BackwardsCompatibilityDeserializationTest.kt @@ -122,11 +122,12 @@ private fun getClassLoaderForBackwardsCompatibilityTest(): ClassLoader { } private fun getClasspathForBackwardsCompatibilityTest(): List { - 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 { diff --git a/settings.gradle b/settings.gradle index bbb2c800420..94bdd469ef1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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