buildscript {
ext {
springBootVersion = '1.4.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
war {
baseName = 'gradleboot'
version = '1.0'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
catalinaAnt
}
dependencies {
[
'org.springframework:spring-context',
'org.springframework.boot:spring-boot-starter-web',
'org.springframework.boot:spring-boot-starter-aop',
'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0',
'org.springframework.boot:spring-boot-configuration-processor'
].each { dep ->
compile(dep) {
exclude module: 'spring-boot-starter-logging'
exclude module: 'logback-classic'
exclude module: 'h2'
exclude module: 'tomcat-jdbc'
}
}
compileOnly('org.postgresql:postgresql')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.projectlombok:lombok:1.16.12')
compile('org.thymeleaf:thymeleaf:3.0.2.RELEASE')
compile('org.thymeleaf:thymeleaf-spring4:3.0.2.RELEASE')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('com.google.code.gson:gson:2.6.1')
compile('commons-fileupload:commons-fileupload:1.3.2')
compileOnly('org.apache.tomcat:tomcat-dbcp:8.0.39')
catalinaAnt "org.apache.tomcat:tomcat-catalina-ant:8.0.39"
}
defaultTasks 'usage'
def baseDir = "."
def war_dir = 'build/libs'
def warking_dir = 'work'
def static_dir = 'src/main/webapp'
def deploy_class = "WEB-INF/classes"
def deploy_libs = "WEB-INF/lib"
def warkingDir = new File(warking_dir)
/**
* USAGE
*/
task usage << {
println 'pull : クリーンナップおよび 共有リポジトリから git pullを行う'
println 'build : プロジェクトのビルド及び war ファイル作成'
println 'deploy : プロジェクトの上書きデプロイ'
println 'clean_deploy : 公開環境を一旦クリーンしてからデプロイ'
println 'reload : tomcat reload'
}
/**
* 作業ディレクトリのcleanup
*/
task cleanup << {
delete "${baseDir}/build"
delete "${baseDir}/${warking_dir}"
}
/**
* 共有リポジトリから git pull する
* cleanup()タスク に依存(まず、clean()する)
*/
task pull(type: Exec,dependsOn: cleanup) {
commandLine "git", "pull"
}
/**
* gradle pull が完了したら 次に、gradle deploy を実施する
*/
/**
* 一時作業用ディレクトリを作る
* build() タスクに依存
*/
task workdir(dependsOn:build) << {
warkingDir.mkdirs()
}
/**
* buildで作成された warファイルを一時作業用ディレクトリに展開
* workdir() に依存
*/
task unzip(type: Copy, dependsOn:workdir) {
def zipFile = file("${baseDir}/${war_dir}/${war.baseName}-${war.version}.war")
from zipTree(zipFile)
into warkingDir
}
/**
* 静的コンテンツをコンテキストrootにコピー
* unzip()タスク に依存
*/
task copycontents(type: Copy, dependsOn:unzip) {
from "${baseDir}/${static_dir}"
into "${baseDir}/${warking_dir}/"
}
/**
* デプロイ先の WEB-INF/lib/*.jar /WEB-INF/classes/*.class を削除してからデプロイ
* 一旦、jar/classをcleanupしてから再度配置し直す
* copycontents()タスク に依存
*/
task clean_deploy(type: Copy, dependsOn:copycontents) {
delete "${deploy_dir}${target_path}/${deploy_libs}"
delete "${deploy_dir}${target_path}/${deploy_class}"
from "${baseDir}/${warking_dir}"
into "${deploy_dir}${target_path}/"
}
/**
* Tomcat環境にデプロイ
* 静的コンテンツのみの更新で、class のバージョンアップ等が無い場合はこちらで十分
* copycontents()タスク に依存
*/
task deploy(type: Copy, dependsOn:copycontents) {
from "${baseDir}/${warking_dir}"
into "${deploy_dir}${target_path}/"
}
/**
* tomcat リロード
*/
task reload() << {
ant.taskdef(
'name':"reload", 'classname':"org.apache.catalina.ant.ReloadTask", 'classpath':configurations.catalinaAnt.asPath
)
ant.reload( 'username':"${tomcat_user}",
'path':"${target_path}", 'password':"${tomcat_passwd}",
'url':"${tomcat_manager_url}" )
}
/**
* tomcat 停止
*/
task stop << {
ant.taskdef(
'name':"stop", 'classname':"org.apache.catalina.ant.StopTask", 'classpath':configurations.catalinaAnt.asPath
)
ant.stop( 'username':"${tomcat_user}",
'path':"${target_path}", 'password':"${tomcat_passwd}",
'url':"${tomcat_manager_url}" )
}
/**
* tomcat 開始
*/
task start << {
ant.taskdef(
'name':"start", 'classname':"org.apache.catalina.ant.StartTask", 'classpath':configurations.catalinaAnt.asPath
)
ant.start( 'username':"${tomcat_user}",
'path':"${target_path}", 'password':"${tomcat_passwd}",
'url':"${tomcat_manager_url}" )
}
|