springboot gradle配置文件,生成jar包

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'

archivesBaseName="ems"
group 'tower'
version '2.0-SNAPSHOT'

tasks.withType(JavaCompile) { 
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
    options.encoding="UTF-8"
}

javadoc { options.encoding = "UTF-8" }

repositories {
        mavenLocal()
        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
configurations {
    // 編譯排除掉內嵌默認的tomcat,使用undertow
    compile.exclude module: 'spring-boot-starter-tomcat'
}

dependencies {
		compile 'org.springframework.boot:spring-boot-starter-web:2.2.5.RELEASE'
        compile 'org.springframework.boot:spring-boot-starter-aop:2.2.5.RELEASE'
        compile 'org.springframework.boot:spring-boot-starter-security:2.2.5.RELEASE'
        compile 'org.springframework.boot:spring-boot-starter-undertow:2.2.5.RELEASE'
        compile 'org.springframework.boot:spring-boot-starter-jdbc:2.2.5.RELEASE'
        
		compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1'
		compile 'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.13'
        compile 'com.google.guava:guava:20.0'
        compile 'io.jsonwebtoken:jjwt:0.9.1'
        compile 'cn.hutool:hutool-all:5.1.2'
		compile 'org.mariadb.jdbc:mariadb-java-client:2.4.0'
}


//生成本應用jar並去除配置文件
task makeJar(type:org.gradle.api.tasks.bundling.Jar) {
    from('build/classes/java/main')
    exclude('*.properties', '*.xml')
}

task deploy(type: Copy) {
    description = 'copy all the binary and config files to deploy dir '
    def destFold='./deploy'
    into(destFold)
    from(configurations.runtime){//本應用依賴jar複製到libs下
        into("libs")
    }
    from("$buildDir/libs"){//本應用代碼jar複製到libs下
        into("libs")
    }
    from("$buildDir/sh"){
        into("sh")
    }
    from("$buildDir/resources/main"){
        into("conf")
    }
    doFirst{
        logger.lifecycle("deploy files to : $destFold")
    }
    doLast{
        logger.lifecycle("deploy success!")
    }
}

build.dependsOn([makeJar])
deploy.dependsOn([build])

執行gradle build命令,則在工程目錄/build/libs中生成本工程的jar包,並且jar中不含配置文件;

執行gradle deploy命令,則工程目錄/deploy目錄下生成 conf, libs目錄,其中分別是配置文件,jar包

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章