Spring Cloud Gradle多模塊打包

以前整理,,每一個人環境不一樣僅供參考java

1.修改父項目的setting.gradle

以下mysql

include 'tools-common:tools-common-base'
findProject(':tools-common:tools-common-base')?.name = 'tools-common-base'
include 'tools-common:tools-common-core'
findProject(':tools-common:tools-common-core')?.name = 'tools-common-core'
include 'tools-common:tools-common-jpa'
findProject(':tools-common:tools-common-jpa')?.name = 'tools-common-jpa'
複製代碼

2.修改父項目build.gradle

增長spring

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'com.bmuschko.docker-spring-boot-application' version '4.6.2'
}

apply plugin: 'com.bmuschko.docker-spring-boot-application'

//排除父項目打包docker
    if (project.subprojects) {
        jar.enabled = false
        bootJar {
            enabled = false
        }
        dockerCreateDockerfile {
            enabled = false
        }
        dockerBuildImage {
            enabled = false
        }
    }

複製代碼

3.在公共類模塊的build.gradle中增長

subprojects {
    apply plugin: 'java-library'

    dockerCreateDockerfile {
        enabled = false
    }
    dockerBuildImage {
        enabled = false
    }
}
複製代碼

4.公共module下子module下修改build.gradle

dependencies {
    implementation 'mysql:mysql-connector-java:8.0.15'
    implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
    implementation project(":${toolsCommon}:${toolsCommonJpa}")
}

docker {
    springBootApplication {
        baseImage = 'openjdk:8-alpine'
        //指定外端口映射到docker內端口
        ports = [8769, 8769]
    }
}

dockerSyncBuildContext {
    doFirst {
        copy {
            from("../${toolsCommon}/${toolsCommonJpa}/build/classes/java/main/store/zabbix/common")
            into('./build/classes/java/main/store/zabbix/common')
        }
    }
}
複製代碼

5.打包docker

  • 5.1 執行 gradle clean
  • 5.2 執行 gradle dockerSyncBuildContext
  • 5.3 執行 gradle dockerBuildImage
相關文章
相關標籤/搜索