标签:url 使用 1.5 链接 files .class att ase XML
使用Gradle构建项目,继承了Ant的灵活和Maven的生命周期管理,不再使用XML作为配置文件格式,采用了DSL格式,使得脚本更加简洁。
构建环境:
- jdk1.6以上,此处使用1.8
- Gradle 4.4.1
- SpringBoot
- idea
下载之后解压到你想存放的目录
1.选择Gradle -> 勾选Java -> 选择SDK(jdk1.8)
1.创建项目后没自动生成src等文件夹
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!";
}
}
执行命令:java -jar build/libs/gradle-demo-0.0.1.jar
Gradle构建SpringBoot并打包可运行的jar配置
标签:url 使用 1.5 链接 files .class att ase XML
原文地址:https://www.cnblogs.com/weizhxa/p/10014543.html