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 ...
随机推荐
- 对webpack的初步研究4
Mode string module.exports = { mode: 'production' }; webpack --mode=production The following string ...
- python编程中的一个经典错误之list引用
请看下面代码 class User: def __init__(self, name, hobby=[]): self.name = name self.hobby = hobby def add_h ...
- 基于canvas实现的高性能、跨平台的股票图表库--clchart
什么是 ClChart? ClChart是一个基于canvas创建的简单.高性能和跨平台的股票数据可视化开源项目.支持PC.webApp以及React Native和Weex等平台.在React Na ...
- AndroidStudio3.4+Unity2018.3,导出JAR包给UNITY使用
环境 Android studio 3.4 + unity2018.3 1,android studio 新建空工程,一切默认,完成.这个空工程只是个壳,它的所有参数都没什么用,它存在的意义是为了后面 ...
- webService接口的py文件打包成exe
(一)webService接口的py文件打包成exe,在python3.5版本.pyInstaller3.2版本.pywin32-219.win-amd64-py3.5版本打包时报错,原因可能是pyi ...
- 将python文件打包成exe可执行文件
操作系统:win8-64位 python版本:3.5 pyInstaller版本:3.2(下载地址:http://www.pyinstaller.org/) pywin32版本:pywin32-219 ...
- 小程序页面间传值(处理传值为对象,简单传值直接用options.XX的形式获取)
bookgoods:function(){ var Json = JSON.stringify(this.data.goods) wx.navigateTo({ url: '/pages/bookgo ...
- JDK 5.0 新增解决线程安全 Callable接口和线程池
在jdk5.0后又新增了两种解决线程安全的问题 一: 实现Callable接口, 实现接口步骤: 1: 创建一个实现Callable接口的实现类 2: 实现Callable接口中的call()方法, ...
- windows 命令端口映射
显示映射列表netsh interface portproxy show all 将本地的1234端口的数据转发至192.168.x.x上的1234端口netsh interface portprox ...
- curl 中关于 CURLINFO_HEADER_SIZE 的 BUG 定位及修复
curl 官方下载页面 CentOS7 默认安装的 curl 版本太低了,需要升级为最新版. 1. 问题描述 对接了一个接口,用来下载 PDF 文件.使用 curl 下载后,文件老是报错无法打开.接口 ...





