我有以下的项目结构:
RootProject
├── lib
└── src
└── main
└── java
└── ...
├── test-project
└── src
└── main
└── java
└── ...
└── build.gradle
我正在尝试遵循Gradle最佳实践来进行多项目构建,因此我将整个构建过程描述在单个build.gradle文件中。
"RootProject"只是一个没有任何代码的根项目,其唯一目的是为其子项目:"lib"和"test-project"提供单个build.gradle文件。
"test-project"是一个SpringBoot项目(微服务),使用"lib"作为编译依赖项。
我的通用build.gradle如下所示:
plugins{
id 'java'
id 'org.springframework.boot' version '2.1.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}
allprojects {
repositories {
jcenter()
}
}
subprojects {
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
group = 'com.xxx.yyy'
version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
project(":lib"){
apply plugin: 'java-library'
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
}
bootJar { enabled = false }
jar { enabled = true }
}
project(":test-project"){
apply plugin: 'java'
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation project(":lib")
implementation ('mysql:mysql-connector-java')
}
}
“lib”和“test-project”都已成功构建。但是,当我尝试在根项目上执行“bootJar”任务(这应该会触发所有子项目上的“build”任务)时,我遇到了以下错误:
Main class name has not been configured and it could not be resolved
有任何想法吗?