【问题标题】:Gradle run failed on multi module micronaut projectGradle 在多模块 micronaut 项目上运行失败
【发布时间】:2021-02-01 07:50:37
【问题描述】:

我有一个下面的项目结构

项目产品和 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.buid.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 中是否有“应用程序”的导入?
  • @IEE1394添加了普通项目的build.gradle,请查看
  • 看起来不错,你的产品 build.gradle 中有 mainClassName 吗?
  • 我已经更新了整个依赖的问题,我在 gradle.build 中有 mainClassName = "fete.bird.ProductApplication"
  • 我也在为新的 micronaut gradle 插件和多模块项目而苦恼,你有没有在单个模块项目中尝试过完全相同的设置?

标签: java gradle intellij-idea build.gradle micronaut


【解决方案1】:

我认为您的项目结构有些不正确。根 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2021-08-18
    • 2017-07-26
    • 2020-11-10
    • 1970-01-01
    • 2019-03-27
    相关资源
    最近更新 更多