Build your project with Gradle, inherit Ant's Flexible and Maven lifecycle management, no longer use XML as a configuration file format, and use the DSL format to make the script more concise.
Build your environment:
- jdk1.6 above, use 1.8 here
- Gradle 4.4.1
- Springboot
- Idea
First, download and install Gradle
Gradle official website
Gradle official website
1. Download Gradle
Download Gradle
gradle version Download
2. Unzip the Gradle
Unzip to the directory you want to store after downloading
Gradle Decompression
3. Setting Gradle Environment Variables
- Create an environment variable gradle_home and point to the installation path of your grdle:
gradle Environment variables
- Add%gradle_home%\bin to your PATH environment variable:
gradle Environment variables
4. Detection Configuration Gradle Configuration DetectionIi. creation of the project
1. Select Gradle, tick Java, select SDK (jdk1.8)
Creating a Project 1
2. Setting GroupID and Artifactid
Creating a Project 2
3. Select our local gradle and set the JVM
! [Create Item 3]] (//upload-images.jianshu.io/upload_images/7228029-4560fdecebd1979d.png?imagemogr2/auto-orient/strip% 7cimageview2/2/w/1240)
iii. Configuration Items
1. The SRC folder is not generated automatically after the project is created.
Configuration Item 1
we create our own folders
Configuration Item 2
2. Configure 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.8targetCompatibility = 1.8jar {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-autoconfigure ' compile Org.springframework.boot: Spring-boot-starter-tomcat ' testcompile Org.springframework.boot: Spring-boot-starter-test ' testcompile "Junit:junit:${ Junitversion} "}
3. Create Springboot startup class
@Controller @SpringBootApplication public class gradledemoapplication {public Static void main (String[] args) { Springapplication.run (Gradledemoapplication.class, args); } @ResponseBody @GetMapping ( "/") public String hello () {return "Hello world!";}}
Iv. Start-up project
- Build Project First
Startup Project 1
Startup Project 2
- Launch Project, click Bootrun
Startup Project 3
Startup Project 4
v. Test Project Test ProjectSix, packaging jar project
Packaging Items 1
Packaging Items 2
Vii. Execution Jar
Execute command: Java-jar Build/libs/gradle-demo-0.0.1.jar
Execute Jar
Catalpaflat
Links: https://www.jianshu.com/p/9231b1f598c5
Source: Jane book
copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Spring Boot Gradle Package executable jar file!