Skip to content

Commit

Permalink
Add min version check (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso authored May 27, 2024
1 parent 5315979 commit dbe7a60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.ARTIFACT_
import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.COMPILER_PLUGIN_ID
import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.GROUP_NAME
import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.KTORFIT_VERSION
import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.MIN_KOTLIN_VERSION
import de.jensklingenberg.ktorfit.gradle.KtorfitGradlePlugin.Companion.SNAPSHOT
import org.gradle.api.Project
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -42,10 +43,17 @@ internal class KtorfitCompilerSubPlugin : KotlinCompilerPluginSupportPlugin {

@OptIn(ExperimentalKotlinGradlePluginApi::class)
override fun getPluginArtifact(): SubpluginArtifact {
checkKotlinVersion(myproject.kotlinExtension.compilerVersion.get())
return SubpluginArtifact(
groupId = GROUP_NAME,
artifactId = ARTIFACT_NAME,
version = "${KTORFIT_VERSION}-${myproject.kotlinExtension.compilerVersion.get()}${SNAPSHOT}"
)
}

private fun checkKotlinVersion(compilerVersion: String) {
if(compilerVersion.split(".")[0] < MIN_KOTLIN_VERSION.split(".")[0]){
error("Ktorfit: Kotlin version $compilerVersion is not supported. You need at least version $MIN_KOTLIN_VERSION")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import java.util.Locale.US

Expand All @@ -18,6 +19,8 @@ class KtorfitGradlePlugin : Plugin<Project> {
const val COMPILER_PLUGIN_ID = "ktorfitPlugin"
const val KTORFIT_VERSION = "2.0.0" // remember to bump this version before any release!
const val SNAPSHOT = "-SNAPSHOT"
const val MIN_KSP_VERSION = "1.0.21"
const val MIN_KOTLIN_VERSION = "2.0.0"
}

override fun apply(project: Project) {
Expand All @@ -36,6 +39,8 @@ class KtorfitGradlePlugin : Plugin<Project> {
val kspVersion = kspPlugin.javaClass.protectionDomain.codeSource.location.toURI().toString()
.substringAfterLast("-").substringBefore(".jar")

checkKSPVersion(kspVersion)

val kspExtension = extensions.findByName("ksp") ?: error("KSP config not found")
val argMethod = kspExtension.javaClass.getMethod("arg", String::class.java, String::class.java)

Expand Down Expand Up @@ -94,6 +99,13 @@ class KtorfitGradlePlugin : Plugin<Project> {

}

private fun checkKSPVersion(kspVersion: String) {
val kspVersionParts = kspVersion.split(".")
if (kspVersionParts[2].toInt() < MIN_KSP_VERSION.split(".")[2].toInt()) {
error("Ktorfit: KSP version $kspVersion is not supported. You need at least version $MIN_KSP_VERSION")
}
}

}

private val Project.kotlinExtension: KotlinProjectExtension?
Expand Down

0 comments on commit dbe7a60

Please sign in to comment.