Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy kotlin-compiler-embeddable dependency to prevent potential Kotlin version conflicts #223

Merged
merged 16 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Please add your entries according to this format.

## Unreleased

- Remove ``kotlin-compiler-embeddable`` dependency to allow update on Kotlin version 1.9.20
simonhauck marked this conversation as resolved.
Show resolved Hide resolved

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

- Kotlin version reverted to 1.9.10
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ binaryCompatibilityValidator = "0.13.2"
detekt = "1.23.3"
diffUtils = "4.12"
junit = "5.10.1"
kotlin = "1.9.10"
kotlin = "1.9.20"
ktfmt-plugin = "0.15.1"
ktfmt = "0.46"
pluginPublish = "1.2.1"
Expand Down
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" } }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is this really needed? I believe the .gradle files inside the resources/ folder are ignored no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calling gradlew :plugin-build:plugin:publishToMavenLocal I get an error about an unconfigured signatory, because the signing task is an implicit dependency.

The publish task is executed from the parent project, so the build.gradle.kts file in the resources directory are unrelated to this.

I am not aware of another easy solution to disable the signing task conditionally for the test.


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=0.0.1-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 "0.0.1-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()
}
}