使用Gradle构建项目,继承了Ant的灵活和Maven的生命周期管理,不再使用XML作为配置文件格式,采用了DSL格式,使得脚本更加简洁。
构建环境:

  1. jdk1.6以上,此处使用1.8
  2. Gradle 4.4.1
  3. SpringBoot
  4. idea

一、下载并安装Gradle

Gradle官网

 
Gradle官网

1.下载Gradle

下载Gradle

 
Gradle版本下载

2.解压Gradle

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

 
Gradle解压

3.设置Gradle环境变量

  1. 创建一个环境变量 GRADLE_HOME,并指向你的Grdle的安装路径:

     
    Gradle环境变量
  2. 添加 %GRADLE_HOME%\bin 到你的PATH 环境变量:
     
    Gradle环境变量

4.检测配置

 
Gradle配置检测

二、创建项目

1.选择Gradle -> 勾选Java -> 选择SDK(jdk1.8)

 
创建项目1

2.设置groupId和artifactid

 
创建项目2

3.选择我们本地的Gradle,并设置JVM
![创建项目3]](//upload-images.jianshu.io/upload_images/7228029-4560fdecebd1979d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

三、配置项目

1.创建项目后没自动生成src等文件夹

 
配置项目1

我们自己创建文件夹

 
配置项目2

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!";
}
}

四、启动项目

  1. 先build项目

     
    启动项目1
     
    启动项目2
  2. 启动项目,点击bootRun
     
    启动项目3
     
    启动项目4

五、测试项目

 
测试项目

六、打包jar项目

打包项目1
 
打包项目2

七、执行jar

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

 
执行jar

作者:CatalpaFlat
链接:https://www.jianshu.com/p/9231b1f598c5
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

Gradle构建SpringBoot并打包可运行的jar配置的更多相关文章

  1. 用gradle把springboot项目打包成jar

    ``` 用gradle把springboot项目打包成jar ```### build.gradle 中添加 buildscript { repositories { mavenLocal() mav ...

  2. Ant打包可运行的Jar包(加入第三方jar包)

    本章介绍使用ant打包可运行的Jar包. 打包jar包最大的问题在于如何加入第三方jar包使得jar文件可以直接运行.以下用一个实例程序进行说明. 程序结构: 关键代码: package com.al ...

  3. Azure Devops实践(5)- 构建springboot项目打包docker镜像及容器化部署

    使用Azure Devops构建java springboot项目,创建镜像并容器化部署 1.创建一个springboot项目,我用现有的项目 目录结构如下,使用provider项目 在根目录下添加D ...

  4. SpringBoot 项目打包后运行报 org.apache.ibatis.binding.BindingException

    今天把本地的一个SpringBoot项目打包扔到Linux服务器上,启动执行,接口一访问就报错,但是在本地Eclipse中启动执行不报错,错误如下: org.apache.ibatis.binding ...

  5. IntelliJ IDEA 打包可运行的 JAR

    ## 构建说明 创建Artifest任务 * File -> Project Structure -> Artifacts -> + JAR* 选择 From module with ...

  6. springboot在eclipse中运行使用开发配置,打包后运行使用生产环境默认配置

    java命令运行springboot jar文件,指定配置文件可使用如下两个参数中其中一个 --spring.config.location=配置文件路径 -Dspring.profiles.acti ...

  7. 使用Gradle构建springboot多模块项目,并混合groovy开发

    idea设置本地gradle 打包: build.gradle //声明gradle脚本自身需要使用的资源,优先执行 buildscript { ext { springBootVersion = ' ...

  8. springboot 项目打包可运行jar文件

    eclipse 运行run as  maven bulid  ,填入package ,运行打包 java -jar xxx.jar

  9. jenkins构建基于gradle的springboot项目CI采坑(采用jar方式部署)

    试了一堆插件,最后用的还是 publish over SSH jenkins基本配置不多说了,就是配置一下git仓储,配置一下gradle执行命令 clean bootRepackage 之后执行Se ...

随机推荐

  1. c++11 默认函数的控制

    1. 类与默认函数: C++中声明自定义的类,编译器会默认生成未定义的成员函数: 构造函数 拷贝构造函数 拷贝赋值函数(operator=) 移动构造函数 移动拷贝函数 析构函数 编译器还会提供全局默 ...

  2. Feign调用远程服务报错:Caused by: java.lang.IllegalStateException: Method getMemberInfo not annotated with HTTP method type (ex. GET, POST)

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ord ...

  3. 重新定义数据库的时刻,阿里云数据库专家带你了解POLARDB

    摘要:POLARDB是阿里云ApsaraDB数据库团队研发的基于云计算架构的下一代关系型数据库,其最大的特色是计算节点与存储节点分离,借助优秀的RDMA网络以及最新的块存储技术.POLARDB不但满足 ...

  4. Django2 + python3 上传图片

    . ├── db.sqlite3 ├── manage.py ├── myImg │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init_ ...

  5. socket函数库简单封装

    #pragma once #ifndef WINSOCK_H #include<WinSock2.h> #pragma comment(lib,"ws2_32.lib" ...

  6. 笨办法学Python(learn python the hard way)--练习程序39-40

    下面是练习39-练习40,基于python3 #ex39.py 1 ten_things = "Apples Oranges Crows Telephone Light Sugar" ...

  7. SSL异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

    jdk 7 http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html jdk 8 http: ...

  8. (转)CoreDNS介绍

    转:https://www.colabug.com/4171614.html 本文介绍 CoreDNS 相关配置以及验证方法,实验环境为 Kubernetes 1.11,搭建方法参考 kubeadm安 ...

  9. Nginx 配置 location 以及 return、rewrite 和 try_files 指令

    正则表达式 Nginx 内置的全局变量 location 前缀字符串及优先级 示例 location 匹配原则 if 和 break 指令 if break return.rewrite 和 try_ ...

  10. Fira Code,可以让不等号!=直接显示出来的字体

    今天看B站某直播间有人写代码C#里一堆不等号直接显示,感觉很神奇,以为是插件还是什么新语法,托人问了下原来是Fira Code字体 https://github.com/tonsky/FiraCode ...