konform-kt / konform

Portable validations for Kotlin
https://www.konform.io
MIT License
651 stars 39 forks source link

get rid of compileOnly #45

Closed jillesvangurp closed 2 years ago

jillesvangurp commented 2 years ago

causing issues with our build

use api instead. I think compileOnly is sort of deprecated in any case.

nlochschmidt commented 2 years ago

api would cause the dependency to become transitive again and I think the user of konform should be free to decide what version of Kotlin to use.

What is your build error looking like?

jillesvangurp commented 2 years ago

I don't think you can avoid dependencies on the standard library. CompileOnly causes issues with multi platform builds. It complains it can't find js and jvm variants.

         > The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of io.konform:konform:0.4.0:
             - jsIrApiElements-published
             - jsLegacyApiElements-published
             - jvmApiElements-published
             - jvmRuntimeElements-published
           All of them match the consumer attributes:
             - Variant 'jsIrApiElements-published' capability io.konform:konform:0.4.0 declares a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
                 - Unmatched attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                     - Provides release status but the consumer didn't ask for it
                     - Provides attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but the consumer didn't ask for it
             - Variant 'jsLegacyApiElements-published' capability io.konform:konform:0.4.0 declares a usage of 'kotlin-api' of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
                 - Unmatched attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                     - Provides release status but the consumer didn't ask for it
                     - Provides attribute 'org.jetbrains.kotlin.js.compiler' with value 'legacy' but the consumer didn't ask for it
             - Variant 'jvmApiElements-published' capability io.konform:konform:0.4.0 declares an API of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                 - Unmatched attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                     - Provides its elements packaged as a jar but the consumer didn't ask for it
                     - Provides release status but the consumer didn't ask for it
             - Variant 'jvmRuntimeElements-published' capability io.konform:konform:0.4.0 declares a runtime of a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                 - Unmatched attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                     - Provides its elements packaged as a jar but the consumer didn't ask for it
                     - Provides release status but the consumer didn't ask for it
           The following variants were also considered but didn't match the requested attributes:
             - Variant 'jsIrRuntimeElements-published' capability io.konform:konform:0.4.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
                 - Incompatible because this component declares a usage of 'kotlin-runtime' of a component and the consumer needed a usage of 'kotlin-api' of a component
                 - Other compatible attribute:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
             - Variant 'jsLegacyRuntimeElements-published' capability io.konform:konform:0.4.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
                 - Incompatible because this component declares a usage of 'kotlin-runtime' of a component and the consumer needed a usage of 'kotlin-api' of a component
                 - Other compatible attribute:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
             - Variant 'metadataApiElements' capability io.konform:konform:0.4.0 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common':
                 - Incompatible because this component declares a usage of 'kotlin-metadata' of a component and the consumer needed a usage of 'kotlin-api' of a component
                 - Other compatible attribute:
                     - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)

0.3.0 did not have that issue

jillesvangurp commented 2 years ago

you might try implementation instead of api

jillesvangurp commented 2 years ago

I copied the konform src into our codebase for now but I'd be happy to test if you do another release.

nlochschmidt commented 2 years ago

Can you link the commit where this fails? Or maybe share the dependencies section of the gradle build file?

jillesvangurp commented 2 years ago

this is a private build of our project. The only difference is changing 0.3.0 to 0.4.0

nlochschmidt commented 2 years ago

Not sure what's going on here. Can you at least share:

I have created a bunch of projects (Multiplatform JVM/JS, JVM, Kotlin/JS) with Kotlin versions 1.5 and 1.6 and the only way I can get this to fail is when using Kotlin 1.5 and the IR backend (Edit: but with a very different error). This is not too worrisome though as the IR backend in Kotlin 1.5 was only beta anyways.

For example a project with this configuration works without issues:

plugins {
    kotlin("multiplatform") version "1.6.21"
}

group = "io.konform.examples"

repositories {
    mavenCentral()
}

kotlin {
    js(BOTH) {
        browser()
        nodejs()
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.konform:konform:0.4.0")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jsMain by getting
        val jsTest by getting
    }
}

Screenshot 2022-06-02 at 16 32 23

nlochschmidt commented 2 years ago

I've tested using Gradle 7.3 and 7.4.

nlochschmidt commented 2 years ago

FYI with regard to

I think compileOnly is sort of deprecated in any case.

This is not the case. compile has been deprecated in favour of api and implementation but compileOnly is exactly for this use-case:

https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

jillesvangurp commented 2 years ago

Sorry for being slow to respond. I tracked down the issue to our use of the legacy js compiler in the end. Sorry about wasting your time. And thank you for your support.

nlochschmidt commented 2 years ago

No worries. Thanks for coming back on this one.