Gradle下如何搭建SpringCloud分布式環(huán)境
Gradle下搭建SpringCloud分布式環(huán)境
1.idea配置好gradle
這一步不必多說, 常規(guī)操作
2.創(chuàng)建一個空的gradle項目

3.創(chuàng)建好后, 注意版本號

4.在本地配置好gradle
將idea的gradle配置改為本地(可選項)

5.修改build.gradle
注意springcloud的版本需要和springboot版本對應, 不然出大問題(不可盲目追新)

推薦

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.qpf'
version '1.0-SNAPSHOT'
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'
}
}
5.添加.gitignore文件
根據需要自己修改內容即可,若idea中沒有該插件,自己添加一個,不往git上提交的可以忽略此步


6.創(chuàng)建子模塊

點gradle

7.檢查子模塊有沒有添加到settings.gradle中
若沒有手動添加

8.處理
將子模塊下的build.gradle文件中除了dependencies中的內容之外全部刪除,添加
apply plugin: 'org.springframework.boot'

例如:
apply plugin: 'org.springframework.boot'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}9.刪除子模塊下多余文件(可選,自己決定)

10.點開右上角的gradle
將與父模塊并列的子模塊刪除

點開父模塊, 可以看到其下的子模塊

說明:刪除模塊時不要直接刪文件,需要從項目中移除然后刪除File->Project Structure…

然后刪除根項目settings.gradle中的include(‘eureka’),最后從項目中刪除子模塊文件即可
提示:若不想修改gradle本地文件編譯,則不用刪除子模塊中gradle文件夾就可以(推薦此方法)
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
IDEA Maven Mybatis generator 自動生成代碼(實例講解)
下面小編就為大家分享一篇IDEA Maven Mybatis generator 自動生成代碼的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
在SpringBoot中配置Thymeleaf的模板路徑方式
這篇文章主要介紹了在SpringBoot中配置Thymeleaf的模板路徑方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08

