I'm having trouble by configuring Swagger 3 on my maven-based Java11 application.
First I have declared in the pom.xml
:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Then, I configure Swagger using Spring Beans:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.***.***.controller.rest"))
.paths(PathSelectors.any())
.build()
.apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfoBuilder().title("***")
.description("***")
.contact(new Contact("**", "www.***.com", "**"))
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.version("1.0.0")
.build();
}
}
And finally, I have declared the module-info.java
requires:
requires springfox.swagger2;
requires springfox.spring.web;
requires springfox.core;
When I try to mvn clean install
, I get the following error:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: the *** module reads package springfox.documentation.service from both springfox.core and springfox.spi
[ERROR] error: module springfox.spring.web reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.swagger2 reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module java.annotation reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.core reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module java.validation reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.beans reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.web reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.context reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module swagger.annotations reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module spring.boot reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.core reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] error: module springfox.spi reads package springfox.documentation.service from both springfox.core and springfox.spi
[ERROR] error: module spring.boot.autoconfigure reads package springfox.documentation.service from both springfox.spi and springfox.core
[ERROR] /private/tmp/***/src/main/java/module-info.java:[1] error: module *** reads package springfox.documentation.service from both springfox.core and springfox.spi
[INFO] 15 errors
[INFO] -------------------------------------------------------------
I guess made a mistake but I can't find it. Could anyone help me?
At this moment, there is no official solution to solve this issue with. however by using maven-shade-plugin and merging the two springfox.core and springfox.spi jar in one package is the best workaround to run your project.
Add this dependency mentioned this URL: https://jitpack.io/#valery1707/springfox-assembly
instead of