springboot+gradle项目打jar包build.gradle配置
废话不多说,直接上代码。
build.gradle里面的配置:
allprojects {
group 'com.sunvua' //程序所在的根目录
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' //springboot版本
}
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}" //将依赖导入jar包
}
}
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 { //打包成功后,jar包名为 TestOneGradle-0.0.1.jar
baseName = 'TestOneGradle' //打成jar包的名字
version = '0.0.1'
manifest {
attributes "Manifest-Version": 1.0,
'Main-Class': 'com.sunvua.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 {
testCompile "junit:junit:${junitVersion}"
compile('org.springframework.boot:spring-boot-starter-web:1.5.9.RELEASE')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
//以下引用 为个人所需
compile('org.springframework.boot:spring-boot-starter-aop:1.5.9.RELEASE')
compile('org.springframework.boot:spring-boot-starter-cache:1.5.9.RELEASE')
compile('org.springframework.boot:spring-boot-starter-websocket:1.5.9.RELEASE')
compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.2.5')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
compile('mysql:mysql-connector-java:8.0.11')
}
项目目录结构:
以上build配置好后,点击idea右上角的gradle
打包结束后,查看下项目的build目录下是否有jar包:
进入最后一步,①:windows+r输入cmd点击enter,cd 进入jar包所在的目录
②: 通过命令行 java -jar 执行jar包,如果出现spring字样,则代表jar包打成功