149

In my build.gradle file I upgraded the version of one dependency (namely: com.db:microservice-commons). After loading the gradle changes, I get the following error message:

> Build file 'C:\Projects\Container\mschmidt\mount\booking-service\standalone\build.gradle' line: 50 > A problem occurred evaluating project ':standalone'. > Could not resolve all files for configuration ':standalone:runtimeClasspath'. > Could not resolve com.db:microservice-commons:2.4.1. Required by: project :standalone project :standalone > project :service > No matching variant of com.db:microservice-commons:2.4.1 was found. The consumer was configured to find a runtime of a library compatible with Java 10, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but: - Variant 'apiElements' capability com.db:microservice-commons:2.4.1 declares a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 10 - Other compatible attribute: - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs) - Variant 'runtimeElements' capability com.db:microservice-commons:2.4.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 10 - Other compatible attribute: - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs) - Variant 'samplessources' capability com.db:microservice-commons:2.4.1: - Incompatible because this component declares documentation 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 environment (preferred optimized for standard JVMs) - Doesn't say anything about its target Java version (required compatibility with Java 10) - Doesn't say anything about its elements (required them packaged as a jar) - Doesn't say anything about its usage (required a runtime) 

Line 50+ of file 'C:\Projects\Container\mschmidt\mount\booking-service\standalone\build.gradle' looks as follows:

manifest { def manifestClasspath = configurations.runtimeClasspath.collect { it.getName() }.join(' ') attributes 'Archiver-Version': 'Plexus Archiver' attributes 'Build-Jdk': org.gradle.internal.jvm.Jvm.current() attributes 'Main-Class': 'com.db.service.standalone.Standalone', 'Class-Path': manifestClasspath } } 

I have no clue what to make of this. Project JDK and Gradle JVM are set to Java 11. This post here: The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally but: ... pertains to the same problem but didn't help me.

Any ideas what's going on here?

11 Answers 11

161

With IntelliJ IDEA, I had to change which JDK Gradle used for running. The original value was JDK 11, I changed it to JDK 17.

Screenshot

Sign up to request clarification or add additional context in comments.

6 Comments

Had the same problem with Android Studio (Electric Eel) in a new project. Updated the Gradle JDK to 11 from the default 8 to fix the project sync.
Thank you! I checked all my project specific JDK version configs and didn't find anything that still pointed to 11, and it was driving me insane. But this fixed the issue for me.
thank you isr, it was this.
Just reference in another version, My JAVA_HOME default ver 14 but project need ver 17 so, this picture help me solve that case to change exactly version for build Thank you so much for your picture
Really appreciate it! It saves my day!
|
46

I found the problem and solved it.

I changed two lines defining the compatibility in the build.gradle file.

From:

compileOptions { sourceCompatibility 10 targetCompatibility 10 } 

To:

compileOptions { sourceCompatibility 11 targetCompatibility 11 } 

7 Comments

Our team also ran into this issue. It was caused by the Gradle version of IntelliJ using another JVM. To solve this go to the preferences: Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM and change the jvm version there
thanks @jvwilge , just spent an hour or so scratching my head after declaring sourceCompatibility/targetCompatibility and still facing this issue!
likewise, thanks @jvwilge, been fighting it for hours.
Thanks @jvwilge I was confused why it still mentions Java 8 even though I have set the JDK to 11 in Project Settings.
@jvwilge thanks man! consider please set you comment as an answer in order to help other people that don't see comments.
|
29

Change the java version which gradle use. As the picture shown below, choose java 11.Then it is ok. enter image description here

2 Comments

For those working on multiple projects with varying version needs, you can set it to "Project SDK" to default to the JDK specified by the project properties (no idea why this isn't the default).
4

The Java version of my JAVA_HOME configuration was 10 before. After changing to Java11, it will be fine.

Comments

3

it is works for me change the code in the app/build.gradle file to this:

android { compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } ... } 

or you can change it in the File/project structure

enter image description here

enter image description here

Comments

3

Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 10

The meaning of this error is gradle wants to run at SDK 11 and SDK provided by your project structure is of version 10

I also faced the same issue while setting up the project in intelliJ,

"Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11"

Solution : I downloaded Java SE Development kit 17 and integrate JDK 17 with project structure. Its worked.

Comments

3

With IntelliJ IDEA, for me it worked with file -> invalidate caches -> invalidate and restart after correcting the version of Gradle JDK/JVM.

Comments

2

in my case, it wasn't about Java Version. it still remain 1.8 (8). if you're using the latest version of Kotlin, you should update your Gradle Version to 6.7.1 or higher in Project Structure. I recommend changing Gradle Plugin Version to the latest Staible Version.

Comments

2

Well, I faced a similar issue

Incompatible because this component declares a component for use during compile-time, compatible with Java 18 and the consumer needed a component for use during runtime, compatible with Java 17

Context: I imported my colleague's project which incorporates Gradle in the project.

Upon opening it in VS code, I saw red squiggly lines. And although VS code's awesome awareness of detecting the build tool, the programming language and automatically suggesting the relevant plugins was a great help for a Gradle newbie like me, but some errors still persisted. And one of them was this.

After skimming through basic concepts like Projects, Plugins, Tasks in the official docs, I could understand the error.

Fix And the fix which worked for me was that in the Gradle Build script (build.gradle) in my main project, a property sourceCompatibility was set to 17. And I had build the project using jdk 18.

This property ensures to use a specific Java version when compiling Java source. When I change this to 18, the project could be built.

Comments

1

For Kotlin programmers using IntelliJ IDEA: I encountered this error when setting up a new project in IntelliJ. I had to specify the Java version inside of build.gradle, like so:

Change this

kotlin { jvmToolchain(8) // The culprit is here. Targeting the wrong, older, Java version. } 

to this

kotlin { jvmToolchain(17) } 

Comments

0

create a file in root system.properties and add there java.runtime.version=17

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.