我是靠谱客的博主 可爱水池,这篇文章主要介绍基于gradle创建springBoot web项目(idea版本)1:创建纯净基于gradle的项目(idea版本)2:设置多模块项目gradle jar管理(idea版本),现在分享给大家,希望可以做个参考。

1:创建纯净基于gradle的项目(idea版本)

我们不基于https://start.spring.io 来创建项目,因为其中有很多配置是我们不需要的;

  • 第一步:FIle–>New–>Project
    在这里插入图片描述
    在这里插入图片描述
    选择Gradle Home 地址;
    在这里插入图片描述

    Finish 结束;

  • 第二步:展示完成项目
    在这里插入图片描述

  • 第三步:创建多模块(module)
    在这里插入图片描述
    在这里插入图片描述
    填写Artifactid 名称(模块名称)
    在这里插入图片描述

    Finish 完成 并删除模块之外的src;
    按照第二步骤再次创建一个模块,完成多模块项目;

    多模块 project项目搭建完成
    在这里插入图片描述

2:设置多模块项目gradle jar管理(idea版本)

  • 第一步:首先删除projectTest项目的最外层 Build.gardle中内容重新配置;
    在这里插入图片描述
    改为:
    在这里插入图片描述
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//应用于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
    在这里插入图片描述
复制代码
1
2
3
4
5
6
7
8
9
10
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") }

讲解

最外层的build.gradle 中分为 两大块 buildscript{} 和 subprojects{};

  1. buildscript{} : 应用于gradle 编译使用 包含
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//应用于gradle 编译 buildscript { //定义 ext { springBootVersion = "2.0.5.RELEASE" } repositories { //maven 中央仓库 mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } }
  1. subprojects{}: 所有子项目的通用配置
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 所有子项目的通用配置 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 } }

在这里插入图片描述

最后

以上就是可爱水池最近收集整理的关于基于gradle创建springBoot web项目(idea版本)1:创建纯净基于gradle的项目(idea版本)2:设置多模块项目gradle jar管理(idea版本)的全部内容,更多相关基于gradle创建springBoot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部