Gradle构建SpringBoot并打包可运行的jar配置
使用Gradle构建项目,继承了Ant的灵活和Maven的生命周期管理,不再使用XML作为配置文件格式,采用了DSL格式,使得脚本更加简洁。
构建环境:
- jdk1.6以上,此处使用1.8
- Gradle 4.4.1
- SpringBoot
- idea
一、下载并安装Gradle

1.下载Gradle

2.解压Gradle
下载之后解压到你想存放的目录

3.设置Gradle环境变量
- 创建一个环境变量 GRADLE_HOME,并指向你的Grdle的安装路径:
Gradle环境变量 - 添加 %GRADLE_HOME%\bin 到你的PATH 环境变量:
Gradle环境变量
4.检测配置

二、创建项目
1.选择Gradle -> 勾选Java -> 选择SDK(jdk1.8)

2.设置groupId和artifactid

3.选择我们本地的Gradle,并设置JVM
![创建项目3]](//upload-images.jianshu.io/upload_images/7228029-4560fdecebd1979d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
三、配置项目
1.创建项目后没自动生成src等文件夹

我们自己创建文件夹

2.配置build.gradle
allprojects {
group 'com.chen'
version '1.0-SNAPSHOT'
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
buildscript {
ext {
springIOVersion = '1.0.0.RELEASE'
springBootVersion = '1.5.9.RELEASE'
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springIOVersion}"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
baseName = 'gradle-demo'
version = '0.0.1'
manifest {
attributes "Manifest-Version": 1.0,
'Main-Class': 'com.chen.GradleDemoApplication'
}
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Brussels-SR6'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.SR4'
}
}
ext {
junitVersion = '4.12'
}
dependencies {
compile 'org.springframework:spring-core'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-autoconfigure'
compile 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile "junit:junit:${junitVersion}"
}
3.创建SpringBoot启动类
@Controller
@SpringBootApplication
public class GradleDemoApplication {
public static void main(String[] args) {
SpringApplication.run(GradleDemoApplication.class, args);
}
@ResponseBody
@GetMapping("/")
public String hello() {
return "Hello World!";
}
}
四、启动项目
- 先build项目
启动项目1
启动项目2 - 启动项目,点击bootRun
启动项目3
启动项目4
五、测试项目

六、打包jar项目

七、执行jar
执行命令:java -jar build/libs/gradle-demo-0.0.1.jar

作者:CatalpaFlat
链接:https://www.jianshu.com/p/9231b1f598c5
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
Gradle构建SpringBoot并打包可运行的jar配置的更多相关文章
- 用gradle把springboot项目打包成jar
``` 用gradle把springboot项目打包成jar ```### build.gradle 中添加 buildscript { repositories { mavenLocal() mav ...
- Ant打包可运行的Jar包(加入第三方jar包)
本章介绍使用ant打包可运行的Jar包. 打包jar包最大的问题在于如何加入第三方jar包使得jar文件可以直接运行.以下用一个实例程序进行说明. 程序结构: 关键代码: package com.al ...
- Azure Devops实践(5)- 构建springboot项目打包docker镜像及容器化部署
使用Azure Devops构建java springboot项目,创建镜像并容器化部署 1.创建一个springboot项目,我用现有的项目 目录结构如下,使用provider项目 在根目录下添加D ...
- SpringBoot 项目打包后运行报 org.apache.ibatis.binding.BindingException
今天把本地的一个SpringBoot项目打包扔到Linux服务器上,启动执行,接口一访问就报错,但是在本地Eclipse中启动执行不报错,错误如下: org.apache.ibatis.binding ...
- IntelliJ IDEA 打包可运行的 JAR
## 构建说明 创建Artifest任务 * File -> Project Structure -> Artifacts -> + JAR* 选择 From module with ...
- springboot在eclipse中运行使用开发配置,打包后运行使用生产环境默认配置
java命令运行springboot jar文件,指定配置文件可使用如下两个参数中其中一个 --spring.config.location=配置文件路径 -Dspring.profiles.acti ...
- 使用Gradle构建springboot多模块项目,并混合groovy开发
idea设置本地gradle 打包: build.gradle //声明gradle脚本自身需要使用的资源,优先执行 buildscript { ext { springBootVersion = ' ...
- springboot 项目打包可运行jar文件
eclipse 运行run as maven bulid ,填入package ,运行打包 java -jar xxx.jar
- jenkins构建基于gradle的springboot项目CI采坑(采用jar方式部署)
试了一堆插件,最后用的还是 publish over SSH jenkins基本配置不多说了,就是配置一下git仓储,配置一下gradle执行命令 clean bootRepackage 之后执行Se ...
随机推荐
- Codeforces 892E Envy
问题描述 小Q正在玩一个叠塔的游戏,游戏的目标是叠出尽可能高的塔.在游戏中,一共有n张矩形卡片,其中第i张卡片的 长度为a_i,宽度为b_i.小Q需要把所有卡片按一定顺序叠成一座塔,要求对于任意一个矩 ...
- [洛谷 P1013] NOIP1998 提高组 进制位
问题描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: L K V E L L K V E K K V E KL V V E KL KK E E K ...
- Oracle RAC运维所遇问题记录二
oracle12c RAC源端与Dataguard目标端实时同步,因业务需求需要在源端增加PDB 1. 源端添加PDB CREATE PLUGGABLE DATABASE kdlxpdb admin ...
- Python3及Pycharm安装
1.首先去python官网下载相应版本的Python安装包.如下: 2.下载完成后解压,双击exe文件进行安装,看到如下界面:Install Now表示默认安装:Customize installat ...
- NOIp 基础数论知识点总结
推荐阅读 NOIp 数学知识点总结: https://www.cnblogs.com/greyqz/p/maths.html Basic 常用素数表:https://www.cnblogs.com/g ...
- Python 装饰器之 functools.wraps
在看 Bottle 代码中看见 functools.wraps 这种用法. def make_default_app_wrapper(name): """ Return ...
- Jsoup代码示例、解析网页+提取文本
使用Jsoup解析HTML 那么我们就必须用到HttpClient先获取到html 同样我们引入HttpClient相关jar包 以及commonIO的jar包 我们把httpClient的基本代码写 ...
- MATLAB 用 imresize() 函数缩小图象是 double 和 uint8 有差别
今天发现一个奇怪的现象. 在用 imresize() 缩小图象时,如果图象时 double 格式的,缩小后会产生不连通的现象. 下面是原图: 对这张图象 img 做 simg = imresize(i ...
- CDN:分类
ylbtech-CDN:分类 1.返回顶部 1. bootstrap Bootstrap 是全球最受欢迎的前端组件库,用于开发响应式布局.移动设备优先的 WEB 项目. 2. feather-icon ...
- Python3.5自带venv创建虚拟环境
为每个程序单独创建虚拟环境可以保证程序只能访问虚拟环境中的包,保持全局解释器的干净整洁,使其只作为创建(更多)虚拟环境的源. windows下创建虚拟环境 Python3.5自带venv,只需执行py ...





