adamko-dev / kotlin-binary-compatibility-validator-mu Goto Github PK
View Code? Open in Web Editor NEWKotlin Binary Compatibility Validator (Mirror Universe)
License: Apache License 2.0
Kotlin Binary Compatibility Validator (Mirror Universe)
License: Apache License 2.0
When applying BCV-MU via the settings plugin, if any subproject is Kotlin/Multiplatform (and probably Android too) KGP is required as a buildscript dependency.
// settings.gradle.kts
buildscript {
dependencies {
// BCV-MU requires the Kotlin Gradle Plugin classes are present
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
}
}
plugins {
id("dev.adamko.kotlin.binary-compatibility-validator") version "$bcvMuVersion"
}
Without this, BCV-MU fails because the KGP classes it uses to fetch the dependencies are missing.
@Fleshgrinder explained more here: Kotlin/binary-compatibility-validator#88 (comment)
Gradle uses classpath isolation with inheritance. The classpath of settings is isolated from the projects, and projects inherit the classpath of their settings. But, an init script for instance is entirely isolated from everything else.
Defining a dependency as
compileOnly
means that our classpath at runtime does not contain the classes we used for compilation. Since settings is isolated from projects we never see their classes, hence, we cannot find the classes we defined ascompileOnly
since nobody added them to our runtime classpath.Us adding the classes to our runtime classpath (either by using
implementation
or combiningcompileOnly
withruntimeOnly
which isimplementation
) would force the dependency upon our consumers. Since projects inherit from settings they would inherit our version of whatever we added to our runtime classpath. This is obviously not what we want.This is a classic problem with Gradle plugins. A good way to solve it is by shadowing the dependencies. We actually do not require a dependency on the Gradle Kotlin DSL, we only require a dependency on its API (
org.jetbrains.kotlin:kotlin-gradle-plugin-api
) (reducing the amount of code to shadow). By using the API we lose theKotlinMultiplatformExtension
class, but we could rewrite the code to use an alternative instead that works just as well:private fun createKotlinMultiplatformTargets(project: Project, extension: BCVProjectExtension) { project.pluginManager.withPlugin("kotlin-multiplatform") { project.extensions.getByType<KotlinTargetsContainer>().targets.forEach { val platformType = it.platformType if (platformType == KotlinPlatformType.jvm || platformType == KotlinPlatformType.androidJvm) { extension.targets.register(it.targetName) { enabled.convention(true) it.compilations.configureEach { inputClasses.from(output.classesDirs) } } } } } }With that it should work. Maybe there is also a way to change the current classloader, since the current thread within the
project.pluginManager.withPlugin("kotlin-multiplatform")
block can load the class. But, I do not know how or if this is at all possible (sounds dangerous, hopefully it is not allowed).
I have attempted to implement the proposed solution. Using KGP-api works well, but I have still encountered problems when using Shadow:
With isEnableRelocation = true
, Gradle doesn't seem to pick up the KotlinTargetsContainer
extension
An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.multiplatform', version: '1.7.20']
> Failed to apply plugin 'org.jetbrains.kotlin.multiplatform'.
> Extension of type 'KotlinTargetsContainer' does not exist. Currently registered extension types: [ExtraPropertiesExtension, BCVProjectExtension, KotlinMultiplatformExtension, KotlinTestsRegistry, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, KotlinArtifactsExtensionImpl]
With With isEnableRelocation = false
and Kotlin/JVM subprojects there's some sort of problem
An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.7.20']
> Failed to apply plugin 'org.jetbrains.kotlin.jvm'.
> Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget.
> Could not generate a decorated class for type KotlinWithJavaTarget.
> Cannot have abstract method KotlinTarget.attributes().
I've also encountered a weird 'wasm' error with Shadowing and Kotlin Multiplatform subprojects
Output:
FAILURE: Build failed with an exception.
* What went wrong:
wasm
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
java.lang.NoSuchFieldError: wasm
at org.jetbrains.kotlin.gradle.targets.js.ir.KotlinWasmTargetPreset.<init>(KotlinWasmTargetPreset.kt:20)
at org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin.setupDefaultPresets(KotlinMultiplatformPlugin.kt:159)
at org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin.apply(KotlinMultiplatformPlugin.kt:79)
at org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin.apply(KotlinMultiplatformPlugin.kt:47)
at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(KotlinPluginWrapper.kt:183)
at org.jetbrains.kotlin.gradle.plugin.AbstractKotlinMultiplatformPluginWrapper.apply(KotlinPluginWrapper.kt:297)
at org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper.apply(PluginWrappers.kt:74)
As there's a workaround, and the settings plugin is still experimental, this isn't critical to fix right now. I'm making this issue to collect any info in once place.
I'll commit the progress I've made so far, and the tests.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates await pending status checks. To force their creation now, click the checkbox below.
io.kotest:kotest-framework-datatest
, io.kotest:kotest-property
, io.kotest:kotest-assertions-core
, io.kotest:kotest-runner-junit5
, io.kotest:kotest-bom
)org.jetbrains.kotlin:kotlin-gradle-plugin-api
, org.jetbrains.kotlin:kotlin-gradle-plugin
).github/workflows/run_gradle_task.yml
actions/checkout v4
gradle/wrapper-validation-action v2
actions/setup-java v4
actions/setup-java v4
android-actions/setup-android v3
gradle/gradle-build-action v3
actions/upload-artifact v4
mikepenz/action-junit-report v4
buildSrc/src/main/kotlin/buildsrc/settings/MavenPublishingSettings.kt
buildSrc/src/main/kotlin/buildsrc/utils/gradle.kt
buildSrc/src/main/kotlin/buildsrc/utils/gradlePluginVariants.kt
buildSrc/src/main/kotlin/buildsrc/utils/intellij.kt
buildSrc/src/main/kotlin/buildsrc/utils/kotlinStdlib.kt
gradle.properties
settings.gradle.kts
build.gradle.kts
buildSrc/settings.gradle.kts
buildSrc/build.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/base.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/gradle-plugin-variants.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/java-base.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/kotlin-gradle-plugin-tests.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/kotlin-gradle-plugin.gradle.kts
buildSrc/src/main/kotlin/buildsrc/conventions/maven-publishing.gradle.kts
gradle/libs.versions.toml
io.github.java-diff-utils:java-diff-utils 4.12
org.jetbrains.kotlinx:binary-compatibility-validator 0.13.2
org.jetbrains.kotlin:kotlin-gradle-plugin 1.9.22
org.jetbrains.kotlin:kotlin-gradle-plugin-api 1.9.22
io.kotest:kotest-bom 5.8.0
io.kotest:kotest-runner-junit5 5.8.0
io.kotest:kotest-assertions-core 5.8.0
io.kotest:kotest-property 5.8.0
io.kotest:kotest-framework-datatest 5.8.0
org.junit:junit-bom 5.10.2
org.junit.jupiter:junit-jupiter 5.10.2
dev.adamko.kotlin.binary_compatibility_validator:bcv-gradle-plugin main-SNAPSHOT
com.gradle.publish:plugin-publish-plugin 1.2.1
com.github.johnrengelman:shadow 8.1.1
dev.adamko.gradle:dev-publish-plugin 0.3.0
modules/bcv-gradle-plugin/build.gradle.kts
modules/bcv-gradle-plugin-functional-tests/build.gradle.kts
gradle/wrapper/gradle-wrapper.properties
gradle 8.6
It's currently possible to run both tasks at the same time. This prevents apiCheck from working, as apiDump will update the dump file.
Running both tasks should trigger an error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.