博客
关于我
gradle系列--打包
阅读量:513 次
发布时间:2019-03-07

本文共 3562 字,大约阅读时间需要 11 分钟。

Spring Boot????

????

?Gradle??Spring Boot??????????

src/main/java/com/example/demo/DemoApplication.java

package com.example.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class DemoApplication {    public static void main(String[] args) {        System.out.println("[DemoApplication.main]: 10");        SpringApplication.run(DemoApplication.class, args);    }}

build.gradle??

plugins {    id 'org.springframework.boot' version '2.3.1.RELEASE'    id 'io.spring.dependency-management' version '1.0.9.RELEASE'    id 'java'}group = 'com.example'version = '0.0.1-SNAPSHOT'sourceCompatibility = '1.8'repositories {    mavenCentral()}dependencies {    implementation 'org.springframework.boot:spring-boot-starter-web'    testImplementation('org.springframework.boot:spring-boot-starter-test') {        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'    }}test {    useJUnitPlatform()}

????

1. ??bootjar???????jar

??build????bootjar????jar?????????/build/libs/?

2. ??jar??????jar

??build????jar????jar???build/libs/...

????

??????jar?????build.gradle?????????????jar???????????build.gradle????

jar {    enabled = true}

3. ?????????

??????task jar?????jar??

???????????????

task makeJar(type: Jar) {    delete 'build/mylib/test.jar'    baseName = 'test'    from('build/classes/java') {        include('**/*.jar')    }    exclude('dir1/', 'file1')    destinationDir = file('build/mylib')}makeJar.dependsOn(build)

??????copy????jar??

task makeJar(type: Copy) {    delete 'build/libs/test.jar'    from('build/intermediates/bundles/release') {        include('classes.jar')    }    into('build/libs')    rename('classes.jar', 'test.jar')}makeJar.dependsOn(build)

??????shadow????fatjar

apply plugin: 'com.github.johnrengelman.shadow'sourceCompatibility = 1.8buildscript {    repositories {        maven {            url "https://plugins.gradle.org/m2/"        }    }    dependencies {        classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"    }}shadowJar {    baseName = 'hello'    classifier = null    version = null    zip64 true    manifest {        attributes 'Main-Class': 'com.example.Main'    }}gradle shadowJar

??build.gradle??

apply plugin: 'idea'apply plugin: 'java'version = '1.0'repositories {    mavenCentral()}project.ext {    springVersion = '4.0.4.RELEASE'    minaVersion = '2.0.13'}dependencies {    compile('com.alibaba:dubbo:2.4.9') {        exclude group: 'org.springframework', module: 'spring'    }    compile("org.apache.zookeeper:zookeeper:3.3.6") {        exclude group: 'javax.jms', module: 'jms'        exclude group: 'com.sun.jmx', module: 'jmxri'        exclude group: 'com.sun.jdmk', module: 'jmxtools'    }    compile("com.github.sgroschupf:zkclient:0.1") {        exclude group: 'javax.jms', module: 'jms'        exclude group: 'com.sun.jmx', module: 'jmxri'        exclude group: 'com.sun.jdmk', module: 'jmxtools'    }    compile "org.springframework:spring-webmvc:$springVersion", "org.springframework:spring-web:$springVersion", ...    fileTree(dir: 'lib', include: '*.jar')}jar {    String someString = ''    configurations.runtime.each { someString = someString + " lib\\"+it.name }    manifest {        attributes 'Main-Class': 'com.each.dubboMainEnd'        attributes 'Class-Path': someString    }}task copyJar(type: Copy) {    from configurations.runtime    into('build/libs/lib')}release(type: Copy, dependsOn: [build, copyJar]) {    from 'conf'    into('build/libs/eachend/conf')}gradle release

转载地址:http://hftjz.baihongyu.com/

你可能感兴趣的文章
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>