一、子模塊打jar包
1、根項目build.gradle配置
buildscript {
ext {
springBootVersion = '2.2.5.RELEASE'
springCloudVersion = 'Hoxton.SR1'
}
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
group 'com.trgis'
version '1.0.0.0'
apply plugin: 'java'
// 指定JDK版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
//指定編碼格式
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
}
subprojects {
//dependency-management 插件
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
//spring bom helps us to declare dependencies without specifying version numbers.
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
jar {
manifest.attributes provider: 'gradle'
}
}
2、子模塊build.gradle配置:dependencies 中的內容根據模塊實際需要配置
apply plugin: 'org.springframework.boot'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
3、還有根項目settings.gradle中引入所有子模塊
rootProject.name = 'demo'
include 'demo-server'
4、雙擊運行gradle->跟項目中->Tasks->build->build
結果如下:會在每個子模塊下創建build文件夾,打包的jar文件在build->libs文件夾中
二、子模塊打docker鏡像
參照https://blog.csdn.net/weixin_41996632/article/details/100705901
給每個子模塊中添加自動打包依賴,執行即可