springboot+gradle项目打jar包build.gradle配置

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包打成功
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值