背景:
我目前有一个多模块(多项目)应用程序存储库。“根”不是可运行的应用程序。它只是我有一个根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"
}
}
}
注意:我
apply false
在我的插件上使用,因为我认为它会阻止 gradle 在使用gradle build
.
我正在尝试做的事情:
我有一个 CI 管道,我想简单地运行gradle build
它应该build
为所有子项目运行任务。但是,在那个过程中,我想忽略为“根”项目运行构建或绕过它,因为它不是一个可运行的应用程序,而只是构建子项目。
任何帮助将不胜感激!:)