Skip to content

Commit

Permalink
Add report Kopy uses a different Kotlin version than the project
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierSegoviaCordoba committed Aug 26, 2024
1 parent a72db3d commit 2beb1d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- `KopyFunctions` to set the functions that will be generated
- report Kopy uses a different Kotlin version than the project

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.javiersc.kotlin.kopy.gradle.plugin

import com.javiersc.gradle.logging.extensions.warnColored
import com.javiersc.kotlin.kopy.args.KopyFunctions
import com.javiersc.kotlin.kopy.args.KopyVisibility
import com.javiersc.kotlin.kopy.compiler.KopyCompilerProjectData
import com.javiersc.kotlin.stdlib.remove
import javax.inject.Inject
import org.gradle.api.Project
import org.gradle.api.provider.Provider
Expand All @@ -16,16 +18,24 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion

public class KopyGradlePlugin
@Inject
constructor(
private val providers: ProviderFactory,
) : KotlinCompilerPluginSupportPlugin {

private val Project.kopy: KopyExtension
get() = the<KopyExtension>()


override fun apply(target: Project) {
target.createExtension()
target.withKotlin { suppressKopyOptInt() }
target.withKotlin {
suppressKopyOptInt()
reportKotlinVersion()
}
target.withKotlinAndroid { dependencies { "api"(kopyRuntime) } }
target.withKotlinJvm { dependencies { "api"(kopyRuntime) } }
target.withKotlinMultiplatform { dependencies { "commonMainApi"(kopyRuntime) } }
Expand All @@ -34,7 +44,7 @@ constructor(
override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>
): Provider<List<SubpluginOption>> {
val kopy: KopyExtension = kotlinCompilation.project.the<KopyExtension>()
val kopy: KopyExtension = kotlinCompilation.project.kopy
return providers.provider {
listOf(
SubpluginOption(
Expand Down Expand Up @@ -65,6 +75,17 @@ constructor(
extensions.create<KopyExtension>(KopyExtension.NAME)
}

private fun Project.reportKotlinVersion() {
val kopyVersion: String =
KopyCompilerProjectData.Version.replaceBeforeLast("+", "").remove("+")
val kotlinVersion: String = getKotlinPluginVersion()
if (kopyVersion == kotlinVersion) return
logger.warnColored {
"Kopy uses a different Kotlin version, $kopyVersion, than the Kotlin Gradle plugin " +
"applied to this project, $kotlinVersion. It may not work as expected."
}
}

private fun Project.withKotlinAndroid(action: Project.() -> Unit) {
pluginManager.withPlugin("org.jetbrains.kotlin.android") { action() }
}
Expand Down

0 comments on commit 2beb1d9

Please sign in to comment.