我有这个项目结构:
-root-project
-settings.gradle
-build.gradle
-subProjectA(spring-boot)
-build.gradle
-subprojectB(spring-boot)
-build.gradle
-subprojectC(spring-boot)
-build.gradle
-commonProject(java library)
-build.gradle
我的根设置很简单。gradle:
rootProject.name = 'root-project'
include 'subProjectA'
include 'subprojectB'
include 'subprojectC'
include 'commonProject'
这是我的根项目build.gradle:
group = 'my.domain'
version = '0.0.1-SNAPSHOT'
ext {
springBootVersion = '2.1.3.RELEASE'
cxfVersion = '3.2.7'
uuidGeneratorVersion = '3.1.5'
commonLang3Version = '3.7'
encacheVersion = '2.6.11'
logstashVersion = '5.2'
}
在每个子项目中,我都有带有这些插件的build.gradle
文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'
我在每个spring-boot
中都有重复的插件和subModule
依赖项,我想将其移至common(root)文件。但是我不知道该怎么办。
答案 0 :(得分:0)
在根build.gradle
文件中,您可以使用subprojects
块来应用通用插件或其他配置,例如通用任务,sourceCompatibility和targetCompatibility,清单信息,测试配置等。如下所示。 / p>
subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
manifest {
attributes (
'Built-By' : System.properties['user.name'],
'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
)
}
}
// Other Configs
}