Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

I am trying to run springboot application using Gradle.
Gradle Version: 5.6.4
Java Home: C:\Program Files\Java\jdk1.8.0_221

I am getting below when using @EnableSwagger2. Please help me to resolve, I could not able to go further, its like i am blocked with this issue. I need to enable swagger.

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

springfox.documentation.spring.web.plugins.DocumentationPluginsManager.createContextBuilder(DocumentationPluginsManager.java:135)

The following method did not exist:

org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;

The method’s class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

jar:file:/C:/Users/Vivek%20K/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/2.0.0.RELEASE/95fc8c13037630f4aba9c51141f535becec00fe6/spring-plugin-core-2.0.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

file:/C:/Users/Vivek%20K/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/2.0.0.RELEASE/95fc8c13037630f4aba9c51141f535becec00fe6/spring-plugin-core-2.0.0.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

My build.gradle

plugins {
id ‘org.springframework.boot’ version ‘2.2.1.RELEASE’
id ‘io.spring.dependency-management’ version ‘1.0.8.RELEASE’
id ‘java’
}

group = ‘com.example’
version = ‘0.0.1-SNAPSHOT’

sourceCompatibility = ‘1.8’
targetCompatibility = ‘1.8’

repositories {
mavenCentral()
}

dependencies {
compile ‘com.h2database:h2’
compile ‘org.springframework.boot:spring-boot-starter-web’
compile ‘org.springframework:spring-aop’
compile group: ‘org.springframework.boot’, name: ‘spring-boot-starter-actuator’, version: ‘2.2.1.RELEASE’
compile group: ‘org.apache.logging.log4j’, name: ‘log4j-core’, version: ‘2.12.1’
compile group: ‘org.apache.logging.log4j’, name: ‘log4j-core’, version: ‘2.12.1’
compile group: ‘io.swagger’, name: ‘swagger-annotations’, version: ‘1.6.0’
compile group: ‘io.springfox’, name: ‘springfox-swagger2’, version: ‘2.0.2’
compile group: ‘io.springfox’, name: ‘springfox-swagger-ui’, version: ‘2.0.2’

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testCompile group: 'junit', name: 'junit-dep', version: '4.+'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.+'

}

test {
useJUnitPlatform()
}

Can somebody help me please to resolve this issue.

This is not a Gradle problem. Some versions of Swagger are not compatible with some versions of Spring Boot. You should consult Swagger issues to see if any of the issues / work-arounds on this work for you or if you’re willing to downgrade Spring Boot to a fully compatible version.