Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

From version 4.7.0 Java 8 compatibility is broken #417

Open
gigitalz opened this issue May 13, 2023 · 6 comments
Open

From version 4.7.0 Java 8 compatibility is broken #417

gigitalz opened this issue May 13, 2023 · 6 comments

Comments

@gigitalz
Copy link

gigitalz commented May 13, 2023

I reveive this error:

* What went wrong:
Execution failed for task ':backend:compileKotlin'.
> Could not resolve all files for configuration ':backend:compileClasspath'.
   > Could not resolve com.github.jershell:kbson:0.4.5.
     Required by:
         project :backend > org.litote.kmongo:kmongo-coroutine-serialization:4.7.0 > org.litote.kmongo:kmongo-serialization-mapping:4.7.0
      > No matching variant of com.github.jershell:kbson:0.4.5 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability com.github.jershell:kbson:0.4.5 declares an API of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
          - Variant 'runtimeElements' capability com.github.jershell:kbson:0.4.5 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

Please also check #391 same issue (and yes it keeps happening).
I am running on java version "1.8.0_301".
I'd like to update but I can't.

@zigzago
Copy link
Member

zigzago commented May 19, 2023

In reproduce the bug.

This is a kbson bug (see jershell/kbson#25)

Workaround:

In your build.gradle.kts:

@CacheableRule
abstract class TargetJvmVersionRule @Inject constructor(val jvmVersion: Int) : ComponentMetadataRule {
    @get:Inject abstract val objects: ObjectFactory

    override fun execute(context: ComponentMetadataContext) {
        context.details.withVariant("apiElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
                attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_API))
            }
        }
    }
}


dependencies {
    components {
        withModule<TargetJvmVersionRule>("com.github.jershell:kbson") {
            params(8)
        }
    }
  ...
}

(source: https://docs.gradle.org/current/userguide/component_metadata_rules.html#basics_of_writing_a_component_metadata_rule)

HTH

@gigitalz
Copy link
Author

gigitalz commented May 26, 2023

I still get an error, but somewhat different?

* What went wrong:
Execution failed for task ':backend:run'.
> Could not resolve all files for configuration ':backend:runtimeClasspath'.
   > Could not resolve com.github.jershell:kbson:0.5.0.
     Required by:
         project :backend > org.litote.kmongo:kmongo-coroutine-serialization:4.9.0 > org.litote.kmongo:kmongo-serialization-mapping:4.9.0
      > No matching variant of com.github.jershell:kbson:0.5.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability com.github.jershell:kbson:0.5.0 declares a library compatible with Java 8, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
          - Variant 'runtimeElements' capability com.github.jershell:kbson:0.5.0 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
@CacheableRule
abstract class TargetJvmVersionRule implements ComponentMetadataRule {
    @Inject abstract ObjectFactory getObjects()

    final Integer jvmVersion
    @Inject TargetJvmVersionRule(Integer jvmVersion) {
    this.jvmVersion = jvmVersion
    }

    void execute(ComponentMetadataContext context) {
        context.details.withVariant("apiElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
                attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_API))
            }
        }
    }
}

dependencies {
    components {
        withModule("com.github.jershell:kbson", TargetJvmVersionRule) {
            params(8)
        }
    }

@gigitalz
Copy link
Author

I tried issuing bot apiElements and runtimeElements, still no luck

* What went wrong:
Execution failed for task ':backend:compileKotlin'.
> Could not resolve all files for configuration ':backend:compileClasspath'.
   > Could not resolve com.github.jershell:kbson:0.5.0.
     Required by:
         project :backend > org.litote.kmongo:kmongo-coroutine-serialization:4.9.0 > org.litote.kmongo:kmongo-serialization-mapping:4.9.0
      > The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'. However we cannot choose between the following variants of com.github.jershell:kbson:0.5.0:
          - apiElements
          - runtimeElements
        All of them match the consumer attributes:
          - Variant 'apiElements' capability com.github.jershell:kbson:0.5.0 declares an API of a library compatible with Java 8, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attribute:
                  - Provides release status but the consumer didn't ask for it
          - Variant 'runtimeElements' capability com.github.jershell:kbson:0.5.0 declares an API of a library compatible with Java 8, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attribute:
                  - Provides release status but the consumer didn't ask for it
                  
                  

code:

@CacheableRule
abstract class TargetJvmVersionRule implements ComponentMetadataRule
    {
    @Inject
    abstract ObjectFactory getObjects()

    final int jvmVersion
    @Inject
    TargetJvmVersionRule(int jvmVersion)
    {
    this.jvmVersion = jvmVersion
    }

    void execute(ComponentMetadataContext context)
        {
        context.details.withVariant("apiElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
                attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_API))
            }
        }

        context.details.withVariant("runtimeElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
                attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_API))
            }
        }
    }
}

dependencies {
    components {
        withModule("com.github.jershell:kbson", TargetJvmVersionRule) {
            params(8)
        }
    }

@gigitalz
Copy link
Author

Looks like it's complaining about an attribute it didn't ask for so I removed it and it went through, code:

@CacheableRule
abstract class TargetJvmVersionRule implements ComponentMetadataRule
    {
    @Inject
    abstract ObjectFactory getObjects()

    final int jvmVersion
    @Inject
    TargetJvmVersionRule(int jvmVersion)
    {
    this.jvmVersion = jvmVersion
    }

    void execute(ComponentMetadataContext context)
        {
        context.details.withVariant("apiElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
            }
        }

        context.details.withVariant("runtimeElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
            }
        }
    }
}

@zigzago
Copy link
Member

zigzago commented May 26, 2023

What is your gradle version ? Tested on my side with gradle 8.1.1

@sarhatabaot
Copy link

This fixed my issue. Running with gradle 8.2.1

Looks like it's complaining about an attribute it didn't ask for so I removed it and it went through, code:

@CacheableRule
abstract class TargetJvmVersionRule implements ComponentMetadataRule
    {
    @Inject
    abstract ObjectFactory getObjects()

    final int jvmVersion
    @Inject
    TargetJvmVersionRule(int jvmVersion)
    {
    this.jvmVersion = jvmVersion
    }

    void execute(ComponentMetadataContext context)
        {
        context.details.withVariant("apiElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
            }
        }

        context.details.withVariant("runtimeElements") {
            attributes {
                attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, jvmVersion)
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants