pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.08k stars 504 forks source link

Cannot run `./gradlew` on cloned repo #2529

Closed mgroth0 closed 5 months ago

mgroth0 commented 5 months ago

Expected Behavior

Cloned project should run ./gradlew without error.

Observed Behavior

After cloning and using ./gradlew, I see this error:

Ktlint_dokka_gradle has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 64.0

I figure my gradle jvm version is wrong. The contribution docs mention setting the project language level to 8. So I tried a new command:

./gradlew -Dorg.gradle.java.home=/Users/matthewgroth/Library/Java/JavaVirtualMachines/corretto-1.8.0_402/Contents/Home/

But this just leads to a different error:

> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':ktlint-api-consumer:classpath'.
      > Could not resolve project :build-logic.
        Required by:
            project :ktlint-api-consumer
         > No matching variant of project :build-logic was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.5' but:
             - Variant 'apiElements' capability :build-logic:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
             - Variant 'mainSourceElements' capability :build-logic:unspecified declares a component, and its dependencies declared externally:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
                     - Doesn't say anything about its usage (required runtime)
             - Variant 'runtimeElements' capability :build-logic:unspecified declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
             - Variant 'testResultsElementsForTest' capability :build-logic:unspecified:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
                     - Doesn't say anything about its usage (required runtime)

Steps to Reproduce

  1. Clone library
  2. Run ./gradlew

Your Environment

Goooler commented 5 months ago

Install JDK 21 and try again.

paul-dingemans commented 5 months ago

And, if you have multiple version of java installed, please make sure that java 17+ is set as active version when invoking ./gradlew.

mgroth0 commented 5 months ago

It seems only jdk 21 works, not 20.