二、idea+gradle配置给springcloud每个子模块打jar包 及 打docker镜像

一、子模块打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

给每个子模块中添加自动打包依赖,执行即可

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章