import groovy.json.JsonSlurper
buildscript {
ext.kotlin_version = '1.0.0'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE'
classpath 'org.springframework:springloaded:1.2.1.RELEASE'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.hidetake:gradle-ssh-plugin:1.6.0'
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'kotlin'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.hidetake.ssh'
war {
baseName = 'sample_server'
version = '1.0.0'
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
ssh.settings {
dryRun = project.hasProperty('dryRun')
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'mysql:mysql-connector-java:5.1.35'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'net.sf.ehcache:ehcache-core:2.6.11'
compile 'org.hibernate:hibernate-ehcache:4.3.8.Final'
compile 'org.json:json:20160212'
compile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit:4.12'
testCompile 'org.springframework.boot:spring-boot-starter-test'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
jar.baseName = 'sample_server'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
configurations {
providedRuntime
}
processResources {
filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
activeProfiles: project.properties['activeProfiles'] ?: "development"
]
}
/**
* deploy setting
*/
task deployWar << {
JsonSlurper slurper = new JsonSlurper()
def deployConfig = slurper.parse(new File('deploy_config.json'))
deployConfig.hosts.each {
def serverHost = it
remotes.create(it) {
role 'web_server'
host = serverHost
user = deployConfig.user
identity = file(deployConfig.key)
}
}
ssh.settings {
knownHosts = allowAnyHosts
}
ssh.run {
session(remotes.role('web_server')) {
put war.getArchivePath().path, "/home/${remote.user}/"
executeSudo("cp ~${remote.user}/${war.getArchiveName()} /usr/share/tomcat8/webapps/ROOT.war")
executeSudo('chown tomcat:tomcat /usr/share/tomcat8/webapps/ROOT.war')
executeSudo "service tomcat8 restart"
execute "rm ~/${war.getArchiveName()}"
}
}
}
deployWar.dependsOn war