基於gradle建立springBoot web項目(idea版本)

1:建立純淨基於gradle的項目(idea版本)

咱們不基於start.spring.io 來建立項目,由於其中有不少配置是咱們不須要的;html

  • 第一步:FIle-->New-->Project java

    在這裏插入圖片描述
    在這裏插入圖片描述
    選擇Gradle Home 地址;
    在這裏插入圖片描述

    Finish 結束;git

  • 第二步:展現完成項目 github

    在這裏插入圖片描述

  • 第三步:建立多模塊(module) web

    在這裏插入圖片描述
    在這裏插入圖片描述
    填寫Artifactid 名稱(模塊名稱)
    在這裏插入圖片描述

    Finish 完成 並刪除模塊以外的src; 按照第二步驟再次建立一個模塊,完成多模塊項目;spring

    多模塊 project項目搭建完成 app

    在這裏插入圖片描述

2:設置多模塊項目gradle jar管理(idea版本)

  • 第一步:首先刪除projectTest項目的最外層 Build.gardle中內容從新配置;
    在這裏插入圖片描述
    改成:
    在這裏插入圖片描述
//應用於gradle 編譯
buildscript {
   //定義
   ext {
       springBootVersion = "2.0.5.RELEASE"
   }
   repositories {
       //maven 中央倉庫
       mavenCentral()
   }

   dependencies {
       // 指定gradle spring boot plugin 版本 用於spring boot 版本依賴控制
       classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

// 全部子項目的通用配置
subprojects {

   //指定中央倉庫 項目使用
   repositories {
       //maven 中央倉庫
       mavenCentral()
   }

   //應用插件
   apply plugin: 'java'

   apply plugin: 'org.springframework.boot'

   //用於spring boot 版本jar依賴
   apply plugin: 'io.spring.dependency-management'

   //指定jdk版本
   sourceCompatibility = 1.8

   //設置group id
   group 'com.project'

   //設置版本
   version '1.0.0'

   description 'projec'

   //依賴
   dependencies {
       testCompile('org.springframework.boot:spring-boot-starter-test')
       compile('org.springframework.boot:spring-boot-starter')
   }

   //這裏必定得要。在多模塊下,否則編譯失敗,由於不會把信賴模塊給打包。
   jar {
       enabled = true
   }
}

複製代碼
  • 第二步:將全部module的build.gradle文件只須要設置本身所須要的jar
    在這裏插入圖片描述
dependencies {
   compile project(":project-core") compile ("org.springframework.boot:spring-boot-starter-web") compile ("io.springfox:springfox-swagger2:2.6.1") compile ("io.springfox:springfox-swagger-ui:2.6.1") //swagger 自定義ui 調用地址:http://${host}:${port}/docs.html 新頁面 compile ("com.github.caspar-chen:swagger-ui-layer:0.0.6") } 複製代碼

講解maven

最外層的build.gradle 中分爲 兩大塊 buildscript{} 和 subprojects{};ide

  1. buildscript{} : 應用於gradle 編譯使用 包含
//應用於gradle 編譯
buildscript {
    //定義
    ext {
        springBootVersion = "2.0.5.RELEASE"
    }
    repositories {
        //maven 中央倉庫
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
複製代碼
  1. subprojects{}: 全部子項目的通用配置
// 全部子項目的通用配置
subprojects {

   //指定中央倉庫 項目使用
   repositories {
       //maven 中央倉庫
       mavenCentral()
   }

   //應用插件
   apply plugin: 'java'

   apply plugin: 'org.springframework.boot'

   apply plugin: 'io.spring.dependency-management'

   //指定jdk版本
   sourceCompatibility = 1.8

   //設置group id
   group 'com.project'

   //設置版本
   version '1.0.0'

   description 'projec'

   //依賴
   dependencies {
       testCompile('org.springframework.boot:spring-boot-starter-test')
       compile('org.springframework.boot:spring-boot-starter')
   }

   //這裏必定得要。在多模塊下,否則編譯失敗,由於不會把信賴模塊給打包。
   jar {
       enabled = true
   }
}

複製代碼
相關文章
相關標籤/搜索