Giter Site home page Giter Site logo

adamko-dev / kotlin-binary-compatibility-validator-mu Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 355 KB

Kotlin Binary Compatibility Validator (Mirror Universe)

License: Apache License 2.0

Kotlin 100.00%
kotlin binary-compatibility gradle-plugin validation

kotlin-binary-compatibility-validator-mu's People

Contributors

asemy avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

kotlin-binary-compatibility-validator-mu's Issues

BCV-MU settings plugin requires Kotlin plugin is defined as a buildscript dependency

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 as compileOnly since nobody added them to our runtime classpath.

Us adding the classes to our runtime classpath (either by using implementation or combining compileOnly with runtimeOnly which is implementation) 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 the KotlinMultiplatformExtension 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.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update dependency dev.adamko.kotlin.binary_compatibility_validator:bcv-gradle-plugin to v0.1.0
  • Update dependency org.jetbrains.kotlinx:binary-compatibility-validator to v0.14.0

Pending Status Checks

These updates await pending status checks. To force their creation now, click the checkbox below.

  • Update kotest to v5.8.1 (io.kotest:kotest-framework-datatest, io.kotest:kotest-property, io.kotest:kotest-assertions-core, io.kotest:kotest-runner-junit5, io.kotest:kotest-bom)
  • Update kotlin monorepo to v1.9.23 (org.jetbrains.kotlin:kotlin-gradle-plugin-api, org.jetbrains.kotlin:kotlin-gradle-plugin)

Detected dependencies

github-actions
.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
gradle
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/gradle-wrapper.properties
  • gradle 8.6

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.