gradle 自定義生成 war
阿新 • • 發佈:2019-01-23
有時候釋出war需要指定和開發環境不同的檔案,這時候需要自己定義war包檔案介面,但是gradle自帶的war外掛打包不夠靈活,可以使用jar任務來自定義。
在本例項中我使用release/resources/log4j.properties 檔案來替換 main/resources/log4j.properties 檔案
改寫自己的build.gralde 使用 gradlew.bat releaseWar 命令來生產自定義
group 'com.bestcover.demo' version '1.0.1.180111' apply plugin: 'groovy' apply plugin: 'java' apply plugin: 'war' sourceCompatibility = 1.8 compileJava{ options.compilerArgs += ['-Xlint:unchecked'] options.encoding = "UTF-8" } compileGroovy{ options.compilerArgs += ['-Xlint:unchecked'] options.encoding = "UTF-8" } compileTestGroovy{ options.compilerArgs += ['-Xlint:unchecked'] options.encoding = "UTF-8" } compileTestJava{ options.compilerArgs += ['-Xlint:unchecked'] options.encoding = "UTF-8" } javadoc{ options.encoding = "UTF-8" } repositories { mavenCentral() } dependencies { compile 'org.mybatis:mybatis:3.2.6' compile 'org.mybatis:mybatis-spring:1.2.2' testCompile group: 'junit', name: 'junit', version: '4.+' } task releaseWar(type:Jar){ metadataCharset "UTF-8" extension "war" into("WEB-INF"){ into("classes"){ from(sourceSets.main.output){ exclude("log4j.properties") } from("src/release/resources") } into("lib"){ from(configurations.compile) } } from(webAppDirName) }