gpt4 book ai didi

spring-boot - 如何忽略多项目 Kotlin Spring Boot 应用程序的根项目的 gradle 构建?

转载 作者:行者123 更新时间:2023-12-02 12:46:31 24 4
gpt4 key购买 nike

背景:

我目前有一个多模块(多项目)应用程序存储库。 “根”是不是 一个可运行的应用程序。它只是我拥有根目录的源目录 build.gradle.kts包含我所有子项目之间通用的依赖项和插件的文件。我的每个子项目都有自己的build.gradle.kts .

所以我的整体项目结构看起来像这样:

my_root_project
- gradle
- wrapper
- gradle-wrapper.jar
- gradle-wrapper.properties
- gradle.build.kts
- settings.gradle.kts
- my_nested_project_a
- src
- main
- kotlin
- my_nested_project_b
...

问题:

每次我跑 gradle build ,我收到一条错误消息:
> Task :bootJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootJar'.
> Main class name has not been configured and it could not be resolved

但是,当我运行我的任何一个子项目(例如 build :my_nested_project_a:build )时,它构建得很好。

当前 Gradle 构建文件

这是我目前在“根” gradle.build.kts 中的内容:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "com.example"
version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

plugins {
id("org.springframework.boot") version "2.1.8.RELEASE" apply false
id("io.spring.dependency-management") version "1.0.8.RELEASE" apply false
kotlin("jvm") version "1.3.50"
kotlin("plugin.spring") version "1.3.50"
kotlin("plugin.jpa") version "1.3.50"
kotlin("plugin.allopen") version "1.3.50"
}

allprojects {
repositories {
maven(url = "https://my.company.com/repo/with/all/the/stuff/I/need")
}

apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "java")
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
}

NOTE: I'm using apply false on my plugins because I thought it would keep gradle from trying to find a main class when building using gradle build.



我正在尝试做的事情:

我有一个 CI 管道,我想简单地运行 gradle build应该运行 build所有子项目的任务。但是,在那个过程中,我想忽略为“根”项目运行构建或绕过它,因为它不是一个可运行的应用程序,而只是构建子项目。

任何帮助将不胜感激! :)

最佳答案

如果你想忽略任务bootJar ,s o 添加以下配置。

bootJar {
enabled = false
}

关于spring-boot - 如何忽略多项目 Kotlin Spring Boot 应用程序的根项目的 gradle 构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58276142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com