vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.6 was found

Open afagund opened this issue 1 year ago • 13 comments

Error when opening a new Java project generated via Spring Initializr.

Environment
  • Operating System: Debian 11
  • JDK version: JDK 17
  • Visual Studio Code version: 1.67.2
  • Java extension version: 1.18.0
Steps To Reproduce
  1. Go to https://start.spring.io/
  2. Generate a project with defaults:

Project: Gradle - Groovy Language: Java Spring Boot: 3.0.6 Packaging: Jar Java: 17

[Please attach a sample project reproducing the error] Please attach logs

Current Result

`The supplied phased action failed with an exception. A problem occurred configuring root project 'todos'. Could not resolve all files for configuration ':classpath'. Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.6. Required by: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.6 No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.6 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6.1' but:

  • Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.6 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 17 and the consumer needed a runtime of a component compatible with Java 11
    • Other compatible attribute:
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  • Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.6 declares a runtime of a component, and its dependencies declared externally:
    • Incompatible because this component declares documentation and the consumer needed a library
    • Other compatible attributes:
      • Doesn't say anything about its target Java version (required compatibility with Java 11)
      • Doesn't say anything about its elements (required them packaged as a jar)
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  • Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.6 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 17 and the consumer needed a runtime of a component compatible with Java 11
    • Other compatible attribute:
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  • Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.6 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 17 and the consumer needed a component compatible with Java 11
    • Other compatible attribute:
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  • Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.6 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 17 and the consumer needed a component compatible with Java 11
    • Other compatible attribute:
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  • Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.6 declares a runtime of a component, and its dependencies declared externally:
    • Incompatible because this component declares documentation and the consumer needed a library
    • Other compatible attributes:
      • Doesn't say anything about its target Java version (required compatibility with Java 11)
      • Doesn't say anything about its elements (required them packaged as a jar)
      • Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')`
Expected Result

No error while running Spring Boot projects generated by Spring Initializr. This works on other IDE's.

Additional Informations

afagund avatar Apr 28 '23 20:04 afagund

Just started a new Initializr project and got same error, Windows, JDK 8

jamiels avatar Apr 29 '23 20:04 jamiels

Solved after changing Gradle JVM version to 17 in IntelliJ. Ctrl + Alt + S > Build, Execution, Deployment > Gradle > Gradle JVM -> java 17

ritesh156ece avatar May 07 '23 06:05 ritesh156ece

Got the same error on VSCode, any solution for this IDE?

JohnD04 avatar May 10 '23 17:05 JohnD04

Got the same error on VSCode, any solution for this IDE?

for vsCode try this : in your settings CTL+ SHIFT+P > preferences:opensettings(ui) type in the search bar : java.import.gradle.java.home fill in the location to the JVM used to run the Gradle daemon. such as for i.E. /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home (path for macOS users) your path should be matching the java version defined in your gradle build of course

I also did a gradle clean and removed the followings folders of the project , I think it is more likely the reason it is now working : rm -r bin .classpath .gradle .nb-gradle .project .settings .vscode .DS_Store .idea

this could be made in a task depending on gradle clean such as : build.gradle.kts - newer kotlin version

tasks.register("distClean") {
	dependsOn("clean")
	doLast {
		delete("bin")
		delete (".classpath")
		delete (".gradle")
		delete (".nb-gradle")
		delete (".project")
		delete (".settings")
		delete (".vscode")
		delete (".DS_Store")
		delete (".idea")
	}
}

build.gradle groovy older version :

task distClean {
 dependsOn("clean")
 doLast {
   delete "bin"
   delete ".classpath"
   delete ".gradle"
   delete ".nb-gradle"
   delete ".project"
   delete ".settings"
   delete ".vscode"
   delete '.DS_Store'
   delete '.idea'
 }
}

then in vsCode CTL+ SHIFT+P > Java : clean java langage server workspace

vifeng avatar May 18 '23 08:05 vifeng

Hi everyone! I'm facing the same issue. If I need to build the project in my terminal, I have to do it using a bash terminal, but I'm working on a project that is throwing this issue in one of my Jenkins steps, when the pull request is building, which is the following: sh "./gradlew coverageReport -Pjacoco.url=${BUILD_URL}jacoco"

The versions that I'm using are: Project: Gradle - Groovy Language: Java 17 Spring Boot: 3.1.1 Gradle: 7.6.1

I have also configured the Gradle JVM setting in Intellij but still got the error. I'd really appreciate some help here. Thanks!

fmignone-appdirect avatar Jul 24 '23 19:07 fmignone-appdirect

I am experiencing the same error:

$ ./gradlew build

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'studybuddy-backend'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.5.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.5
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.5 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2.1' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 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 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - 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.2.1')
          - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.5 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 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.1.5 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 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 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 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.5 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - 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.2.1')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s

And this is my build.gradle:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.1.4'
	id 'io.spring.dependency-management' version '1.1.3'
}

group = 'dev.gustavoteixeira'
version = '0.0.1'

java {
	sourceCompatibility = '17'
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	implementation 'com.auth0:java-jwt:4.0.0'
	implementation 'org.projectlombok:lombok'

	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
	annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
	annotationProcessor 'org.projectlombok:lombok'

	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.security:spring-security-test'
	testImplementation 'org.springframework.boot:spring-boot-testcontainers'
	testImplementation 'org.testcontainers:junit-jupiter'
	testImplementation 'org.testcontainers:mongodb'
}

tasks.named('test') {
	useJUnitPlatform()
}

gustavoteixeirah avatar Oct 23 '23 03:10 gustavoteixeirah

Similar issue for me with boot version 3.1.5. Building on Java 17 and consumer needed Java 14.

./gradlew --version 
...
------------------------------------------------------------
Gradle 8.4
------------------------------------------------------------

Build time:   2023-10-04 20:52:13 UTC
Revision:     e9251e572c9bd1d01e503a0dfdf43aedaeecdc3f

Kotlin:       1.9.10
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.2 (Oracle Corporation 17.0.2+8-86)
OS:           Mac OS X 13.6 x86_64

Fix that worked for me:

  • delete .gradle
  • delete ~/.gradle
  • restart

marcinpz avatar Oct 23 '23 12:10 marcinpz

image As mentioned on https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html for springboot 3.1.5 and above atleast java 17 is required so java version below 17 a little older version of spring boot is preferred.

ayushsaun avatar Oct 28 '23 11:10 ayushsaun

Almost same as @ritesh156ece, on my version of IntelliJ, I had to go to Settings > Build, Execution, and Deployment > Build Tools > Gradle > Gradle JVM

tweissin avatar Nov 18 '23 10:11 tweissin

Googling for the error brought me here. In my case, the issue was that I had left JAVA_HOME to point to Java 11 and rest all to Java 17. Updating JAVA_HOME worked.

techpavan avatar Nov 22 '23 10:11 techpavan

Got the same problem with github action. Solved by adding required JAVA version in github flows deploy.yml

      - name: Setup Java
        uses: actions/setup-java@v2
        with:
          distribution: 'temurin'
          java-version: '21'

hoangntv-1399 avatar Apr 08 '24 16:04 hoangntv-1399

Same problem with gradle.

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.3.2'
	id 'io.spring.dependency-management' version '1.1.6'
...
java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(22)
	}
}

Note for gradle: 1 - You have to wait for a box to appear with something related to @nulls annotations in java and something else, I didn't have time to read it "with the eagerness I had for it to work" 2 - Accept a box where that appears 3 - A folder called .gradle will be created 4 - Wait for the java project to load

Finally this error will no longer occur.

drakgoku avatar Aug 02 '24 20:08 drakgoku