![](/img/trans.png)
[英]swagger ui not accessible with micronaut multi-module project gradle build
[英]Gradle run failed on multi module micronaut project
我有一個以下項目結構
項目產品和API網關共享公共項目。 由於在 settings.gradle 中我包含了如下項目
rootProject.name = 'src'
include 'common', 'fetebird-apigateway', 'fete-bird-product'
在 API 網關 build.gradle 中,我包含了以下依賴項
dependencies {
implementation project(':common')
}
在產品 build.gradle 中,我包含以下依賴項\\
plugins {
id "com.github.johnrengelman.shadow" version "6.0.0"
id "io.micronaut.application" version '1.0.3'
}
version "0.1"
group "fete.bird"
repositories {
mavenCentral()
jcenter()
}
micronaut {
runtime "netty"
testRuntime "junit5"
processing {
incremental true
annotations "fete.bird.*"
}
}
dependencies {
annotationProcessor("io.micronaut.openapi:micronaut-openapi")
annotationProcessor("io.micronaut.data:micronaut-data-processor")
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut:micronaut-runtime")
implementation("javax.annotation:javax.annotation-api")
implementation("io.micronaut:micronaut-http-client")
implementation("io.swagger.core.v3:swagger-annotations")
implementation("io.micronaut:micronaut-discovery-client")
implementation("io.micronaut.rxjava3:micronaut-rxjava3")
implementation("io.micronaut.kafka:micronaut-kafka")
implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
implementation("io.micronaut.mongodb:micronaut-mongo-reactive")
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.1")
implementation project(':common')
runtimeOnly("ch.qos.logback:logback-classic")
}
mainClassName = "fete.bird.ProductApplication"
java {
sourceCompatibility = JavaVersion.toVersion('15')
targetCompatibility = JavaVersion.toVersion('15')
}
tasks.withType(JavaCompile) {
options.fork = true
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
}
common.build.gradle
plugins {
id 'java'
}
group 'fete.bird'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
產品主類
public class ProductApplication {
public static void main(String[] args) {
Micronaut.run(ProductApplication.class, args);
}
}
當我使用命令行或 intellj idea 運行單個項目時
$ gradle build
或者
$ gradle run
例外
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/Users/macbook/Projects/FeteBird-Microservice/src/fete-bird-product/build.gradle' line: 37
* What went wrong:
A problem occurred evaluating root project 'fete-bird-product'.
> Project with path ':common' could not be found in root project 'fete-bird-product'.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring root project 'fete-bird-product'.
> Failed to notify project evaluation listener.
> Cannot query the value of extension 'application' property 'mainClass' because it has no value available.
> Cannot query the value of extension 'application' property 'mainClass' because it has no value available.
* 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.
==============================================================================
問題在於Project with path ':common' could not be found in root project 'fete-bird-product'.
我相信你的項目結構有點不正確。 根 build.gradle 應該在項目的根目錄中,而不是在src
。
我前段時間創建了這個repo ,它利用了多模塊設置。 如果需要,您可以忽略 BuildSrc 模塊。
.
├── build.gradle.kts
├── moduleA
│ └── build.gradle.kts
├── moduleB
│ └── build.gradle.kts
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.