mn --version
| Micronaut Version: 1.3.0.M1
| JVM Version: 13.0.1
My build.gradle is attached here:
build.gradle
--------------------------------------
plugins {
id "net.ltgt.apt-eclipse" version "0.21"
id "com.github.johnrengelman.shadow" version "5.1.0"
id "application"
}
version "0.1"
group "hello.world"
repositories {
mavenCentral()
maven { url "https://jcenter.bintray.com" }
}
configurations {
// // for dependencies that are needed for development only
developmentOnly
}
dependencies {
annotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
annotationProcessor "io.micronaut:micronaut-inject-java"
annotationProcessor "io.micronaut:micronaut-validation"
annotationProcessor "io.micronaut.configuration:micronaut-openapi"
compile "io.swagger.core.v3:swagger-annotations"
implementation platform("io.micronaut:micronaut-bom:$micronautVersion")
implementation "io.micronaut:micronaut-inject"
implementation "io.micronaut:micronaut-validation"
implementation "io.micronaut:micronaut-runtime"
implementation "javax.annotation:javax.annotation-api"
implementation "io.micronaut:micronaut-http-server-netty"
implementation "io.micronaut:micronaut-http-client"
runtimeOnly "ch.qos.logback:logback-classic:1.2.3"
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testAnnotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation platform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "io.micronaut.test:micronaut-test-junit5"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
}
test.classpath += configurations.developmentOnly
mainClassName = "hello.world.Application"
// use JUnit 5 platform
test {
useJUnitPlatform()
}
tasks.withType(JavaCompile){
options.encoding = "UTF-8"
options.compilerArgs.add('-parameters')
options.fork = true
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
}
shadowJar {
mergeServiceFiles()
}
run.classpath += configurations.developmentOnly
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
构建gradle时,会收到以下警告:
gradle build
> Task :compileJava
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
Note: Generating OpenAPI Documentation
Note: Writing OpenAPI YAML to destination: file:///Users/vkandas/Documents/OneDrive%20-%20Walmart%20Inc/Workspace2/hello-world/build/classes/java/main/META-INF/swagger/hello-world-0.0.yml
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
Note: Creating bean classes for 9 type elements
3 warnings
> Task :compileTestJava
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
warning: Supported source version 'RELEASE_11' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '13'
Note: Creating bean classes for 2 type elements
3 warnings
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 11s
12 actionable tasks: 12 executed
PROBLEM:
The swagger-ui is not generated. Also the static resources of swagger, although generated, is not served by micronaut.
application.yml
micronaut:
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**
application:
name: hello-world
Starting application is OK:
gradle run
> Task :run
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
00:46:57.637 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 810ms. Server Running: http://localhost:8080
Starting V8 000
Starting V8 111
0
1
2
3
<=========----> 75% EXECUTING [1m 26s]
> :run
----------问题---------
为什么不生成swagger-ui视图?看起来有些冲突,但不确定它们是什么。我正在做一个简单的测试,看看如何生成swagger-ui。
请提供一些帮助。挣扎了几个小时。
答案 0 :(得分:0)
似乎您需要使用micronaut-openai库的更高版本。
将gradle文件中的依赖项更改为
annotationProcessor "io.micronaut.configuration:micronaut-openapi:1.3.3"
答案 1 :(得分:0)
在 Micronaut OpenAPI/Swagger Support docs 中,它说 Kapt scope
用于 Kotlin
dependencies {
kapt("io.micronaut.openapi:micronaut-openapi:2.4.0")
implementation("io.swagger.core.v3:swagger-annotations:2.1.9")
}