基于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
   }
}

复制代码
相关文章
相关标签/搜索