forked from cortinico/ktfmt-gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove legacy
kotlin-compiler-embeddable
dependency to prevent pote…
…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
1 parent
8737057
commit 09b573b
Showing
6 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
plugin-build/plugin/src/test/java/com/ncorti/ktfmt/gradle/PluginVersionCompatibilityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
plugin-build/plugin/src/test/resources/jvmProject-version-compatibility/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } |
9 changes: 9 additions & 0 deletions
9
plugin-build/plugin/src/test/resources/jvmProject-version-compatibility/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
rootProject.name = ("test-fixtures") | ||
|
||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} |