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 ...
随机推荐
- 【leetcode】1028. Recover a Tree From Preorder Traversal
题目如下: We run a preorder depth first search on the root of a binary tree. At each node in this traver ...
- sublime text3 Package Control 插件安装及推荐(MAC)
参考: https://www.zhihu.com/question/36233553 https://www.cnblogs.com/zuoan-oopp/p/6692797.html 插件推荐 因 ...
- webdriver显式和隐式等待、强制等待
implicitly_wait() 方法是隐式等待,用来设置超时,一般把implicitly_wait()方法调用在加载测试地址后,等待所测试的应用程序加载WebDriverWait() 是显式等待, ...
- python全栈开发,Day42(Thread类的其他方法,同步锁,死锁与递归锁,信号量,事件,条件,定时器,队列,Python标准模块--concurrent.futures)
昨日内容回顾 线程 什么是线程? 线程是cpu调度的最小单位 进程是资源分配的最小单位 进程和线程是什么关系? 线程是在进程中的一个执行单位 多进程 本质上开启的这个进程里就有一个线程 多线程 单纯的 ...
- unique && stl的全排列
stl的全排列: 看代码. #include<iostream> #include<cstdio> #include<algorithm> #include< ...
- 2019 上海网络赛 J stone name (01背包)
题目:https://nanti.jisuanke.com/t/41420 题意:给你一个集合,然后让你拆成两个集合 x,y 求满足 x>y && x-(x集合中最小 ...
- 全国地区sql表
/** * 中国省市区--地区SQL表 */ CREATE TABLE `rc_district` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMEN ...
- UVA 11752 The Super Powers(暴力)
题目:https://cn.vjudge.net/problem/UVA-11752 题解:这里只讨论处理越界的问题. 因为题目最上界是 264-1. 我们又是求次幂的. 所以当我们就可以知道 i 的 ...
- JAVA一切皆对象之包装类、自动装箱、自动拆箱
首先封装一个基本数据类型int, class P{ private int number; //封装一个私有的->基本数据类型 public P(){} public P(int number) ...
- linux文件夹 权限为所有用户可 读写
使用命令: sudo chmod dirname -R





