Skip to content

Commit

Permalink
Remove legacy kotlin-compiler-embeddable dependency to prevent pote…
Browse files Browse the repository at this point in the history
…ntial Kotlin version conflicts (cortinico#223)

* add test to verify that the plugin can be applied to projects with different kotlin versions and kotlin version 1.9.10

* increase kotlin version to 1.9.20 to showcase the failing PluginVersionCompatibilityTest to a project with kotlin version 1.9.10

* remove kotlin compiler embeddable dependency to apply plugin successfully to projects with different kotlin versions

* remove formatting changes

* add changes to changelog

* add changelog entry for kotlin version bump

* bump version of this plugin for version compatibility test to maximum to prevent conflicts with renovate

* Update dependency com.android.library to v8.1.3 (cortinico#224)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency com.android.library to v8.1.4 (cortinico#225)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency com.github.ben-manes.versions to v0.50.0 (cortinico#226)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency org.jetbrains.kotlin:kotlin-compiler-embeddable to v1.9.21 (cortinico#228)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update kotlin to v1.9.21 (cortinico#229)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* rebase commit, resolve conflicts

* remove formatting changes

* remove unused kotlin-compiler-embeddable dependency

* Update CHANGELOG.md

---------

Co-authored-by: Simon Hauck <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Nicola Corti <[email protected]>
  • Loading branch information
4 people authored Nov 24, 2023
1 parent 8737057 commit 09b573b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Please add your entries according to this format.

## Unreleased

- Remove legacy `kotlin-compiler-embeddable` dependency to prevent potential Kotlin version conflicts
- Kotlin to 1.9.21

## Version 0.15.1 *(2023-10-31)*

- Kotlin version reverted to 1.9.10
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
jupiter = { module = "org.junit.jupiter:junit-jupiter" }
jupiter-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
truth = { module = "com.google.truth:truth", version.ref = "truth" }
diffUtils = { module = "io.github.java-diff-utils:java-diff-utils", version.ref = "diffUtils" }
ktfmt = { module = "com.facebook:ktfmt", version.ref = "ktfmt" }
7 changes: 2 additions & 5 deletions plugin-build/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ dependencies {
.classpath.asFiles.first()
)
)
constraints {
implementation(libs.kotlin.compiler.embeddable) {
because("Clash in Kotlin compiler versions - See https://youtrack.jetbrains.com/issue/KT-54236")
}
}
}

gradlePlugin {
Expand All @@ -99,6 +94,8 @@ signing {
useInMemoryPgpKeys(signingKey, signingPwd)
}

tasks.withType<Sign>().configureEach { onlyIf { project.properties["skip-signing"] != "true" } }

tasks.withType<Test> {
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.ncorti.ktfmt.gradle

import com.google.common.truth.Truth.assertThat
import java.io.File
import java.nio.file.Path
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

internal class PluginVersionCompatibilityTest {

@TempDir lateinit var tempDir: File

private val pluginBuildDirectory = Path.of("./", "../")

@BeforeEach
fun setUp() {
File(tempDir, "src/main/java").mkdirs()
File("src/test/resources/jvmProject-version-compatibility").copyRecursively(tempDir)
}

@ParameterizedTest
@ValueSource(strings = ["1.7.20", "1.9.10", "1.9.20"])
fun `plugin can be applied to projects with different kotlin versions`(kotlinVersion: String) {
// Prevent sharing of classpath
publishPluginToMavenLocal()

replaceKotlinVersion(kotlinVersion)

createTempFile(content = "val answer = 42\n")
val result =
GradleRunner.create()
.withProjectDir(tempDir)
.withArguments("ktfmtCheckMain", "--info")
.build()

assertThat(result.task(":ktfmtCheckMain")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

private fun publishPluginToMavenLocal() {
GradleRunner.create()
.withProjectDir(pluginBuildDirectory.toFile())
.withArguments(
"plugin:publishToMavenLocal",
"-PVERSION=99.99.99-compatibility-check",
"-Pskip-signing=true"
)
.build()
}

private fun replaceKotlinVersion(version: String) {
val file = tempDir.resolve("build.gradle.kts")
val updatedKotlinVersion = file.readText().replace("KOTLIN_VERSION_PLACEHOLDER", version)

file.writeText(updatedKotlinVersion)
}

private fun createTempFile(
@Language("kotlin") content: String,
fileName: String = "TestFile.kt",
path: String = "src/main/java"
) =
File(File(tempDir, path), fileName).apply {
createNewFile()
writeText(content)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
kotlin("jvm") version "KOTLIN_VERSION_PLACEHOLDER"
id("com.ncorti.ktfmt.gradle") version "99.99.99-compatibility-check"
}

repositories { mavenCentral() }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = ("test-fixtures")

pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}

0 comments on commit 09b573b

Please sign in to comment.