jar{
    enabled false
}

bootJar {
    enabled true
}

dependencies {
    //引入smartcity-common模块
    implementation project(':smartcity-common')
    //implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-oauth2'
    implementation 'org.springframework.cloud:spring-cloud-starter-security'
    implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
    implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka'
    implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery'
    implementation 'com.alibaba.cloud:spring-cloud-starter-dubbo'
    

    compile('mysql:mysql-connector-java:5.1.47')

    compile('org.apache.commons:commons-lang3:3.4')

    //数据源连接池
    //compile('com.alibaba:druid:1.1.6')
    compile('com.alibaba:druid-spring-boot-starter:1.1.9')

    //分页插件
    compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.2.10')

    //poi
    compile 'org.apache.poi:poi:3.17'
    compile 'org.apache.poi:poi-ooxml:3.17'
    compile 'org.apache.poi:poi-ooxml-schemas:3.17'
    //jxls
    //compile 'org.jxls.jxls:2.4.6'
    compile 'org.jxls:jxls-poi:1.0.16'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}


task deploy(dependsOn:bootJar){
    doLast {
        println 'deploy sit...'
        ssh.settings {
            knownHosts = allowAnyHosts
        }
        ssh.run {
            session(remotes.sitServer){
                put from: 'build/libs/smartcity-admin.jar', into: '/opt/sit/smartcity-admin'
                def result = execute '/opt/sit/stop-port.sh 8325'
                println result
                execute 'nohup java -jar /opt/sit/smartcity-admin/smartcity-admin.jar --spring.profiles.active=sit >/dev/null &'
            }
        }
    }
}

task deploySit(dependsOn:bootJar){
    def active = 'sit'
    def applicationName = 'smartcity-admin'
    def targetDir = '/opt/sit/smartcity-admin'
    doLast {
        println "deploy ${applicationName} ${active}..."
        ssh.settings {
            knownHosts = allowAnyHosts
        }
        ssh.run {
            session(remotes.sitServer){
                put from: "build/libs/${jar.archiveName}", into: "${targetDir}"
                execute """
                        source /root/.bash_profile;
                        kill `ps aux | grep -i ${applicationName} | grep -v grep | awk '{print \$2}'`;
                        nohup java -jar ${targetDir}/${jar.archiveName} --spring.profiles.active=${active}   >/dev/null &
                """
            }
        }
    }
}

task deployUat(dependsOn:bootJar){
    def active = 'uat'
    def applicationName = 'smartcity-admin'
    def targetDir = '/opt/uat/smartcity-admin'
    doLast {
        println "deploy ${applicationName} ${active}..."
        ssh.settings {
            knownHosts = allowAnyHosts
        }
        ssh.run {
            session(remotes.uatServer155){
                put from: "build/libs/${jar.archiveName}", into: "${targetDir}"
                execute """
                        source /root/.bash_profile;
                        kill `ps aux | grep -i ${applicationName} | grep -v grep | awk '{print \$2}'`;
                        nohup java -jar ${targetDir}/${jar.archiveName} --spring.profiles.active=${active}   >/dev/null &
                """
                //execute 'kill `ps aux | grep -i smartcity-admin | grep -v grep | awk \'{print \\$2}\'`;'
                //execute 'nohup /usr/java/jdk1.8.0_211/bin/java -jar /opt/uat/smartcity-admin/smartcity-admin.jar --spring.profiles.active=uat >/dev/null &'
            }
        }
    }
}
def releaseTime() {
    return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00"))
}
archivesBaseName = "smartcity-admin-${releaseTime()}"