原先在公司做项目时,写了一个简单的基于gradle部署项目的脚本,今天翻出来记录一下 

一、build.gradle

buildscript {
    ext {
        env = System.getProperty("env") ?: "test"
        jvmArgs = "-server -Xms128m -Xmx128m -XX:NewRatio=4  -XX:SurvivorRatio=16 -XX:MaxTenuringThreshold=15 -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled  -XX:+ExplicitGCInvokesConcurrent -XX:+DoEscapeAnalysis -XX:-HeapDumpOnOutOfMemoryError"
        if (env == "prod") {
            jvmArgs = "-server -Xms2g -Xmx2g -XX:NewRatio=4  -XX:SurvivorRatio=16 -XX:MaxTenuringThreshold=15 -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled  -XX:+ExplicitGCInvokesConcurrent -XX:+DoEscapeAnalysis -XX:-HeapDumpOnOutOfMemoryError"
        }
        userHome = System.getProperty("user.home")
        osName = System.getProperty("os.name")
    }

    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.hidetake:gradle-ssh-plugin:2.7.0'
        classpath 'co.tomlee.gradle.plugins:gradle-thrift-plugin:0.0.6'
    }
}

allprojects {
    apply plugin: 'idea'
    apply plugin: 'eclipse'
    apply plugin: 'org.hidetake.ssh'
    group = 'com.mwee.information.core'
    version = '1.0-SNAPSHOT'
    ssh.settings {
        timeoutSec = 60
        knownHosts = allowAnyHosts
    }
    defaultTasks 'clean', 'copyPartDependencies'

    //排除Log4j依赖
    configurations {
        compile.exclude module: 'slf4j-log4j12'
        compile.exclude module: 'org.apache.logging.log4j'
        compile.exclude module: 'log4j'
        all*.exclude group: 'org.apache.logging.log4j'
        all*.exclude group: 'log4j'
    }


}

subprojects {
    apply plugin: 'java'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    repositories {
        mavenLocal()
        maven { url "http://114.80.88.52:9001/nexus/content/groups/public/" }
    }
    sourceSets {
        main {
            java {
                srcDirs = ['src/main/java']
            }
            resources {
                srcDirs = ["src/main/resources", "src/main/profile/$env"]
            }
        }
    }
    dependencies {
        compile("org.codehaus.groovy:groovy-all:2.2.1")
        compile 'org.codehaus.groovy:groovy-backports-compat23:2.4.5'
        compile("org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE")
        compile("org.apache.commons:commons-lang3:3.4")
        compile("org.apache.commons:commons-collections4:4.1")
        compile "org.apache.commons:commons-pool2:2.4.2"
        compile group: 'com.alibaba', name: 'fastjson', version: '1.2.12'
        // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
        compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
        // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
        compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.6'
        compile group: 'org.aspectj', name: 'aspectjrt', version: '1.8.7'
        compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.7'
        compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.1'
        compile(group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26')
        compile group: 'org.projectlombok', name: 'lombok', version: '1.16.8'
        compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5'
        compile group: 'com.google.guava', name: 'guava', version: '18.0'
        compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
        compile group: 'com.jcraft', name: 'jsch', version: '0.1.53'
        testCompile group: 'junit', name: 'junit', version: '4.12'
        testCompile "org.springframework:spring-test:4.3.4.RELEASE"
        compile "javax.validation:validation-api:1.1.0.Final"
        compile "org.hibernate:hibernate-validator:5.2.4.Final"
    }
    //gradle utf-8 compile
    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    task copyAllDependencies(type: Copy, dependsOn: jar) {
        description = "拷贝全部依赖的jar包"
        from configurations.runtime
        into 'build/libs'
    }

    task copyPartDependencies(type: Copy, dependsOn: jar) {
        description = "拷贝部分依赖的jar"
        from configurations.runtime
        into 'build/libs'
        doLast {
            file("build/libs").listFiles({ !it.name.endsWith("-SNAPSHOT.jar") } as FileFilter).each {
                it.delete()
            }
        }

    }

}
View Code

相关文章:

  • 2021-10-06
  • 2021-12-29
  • 2021-10-30
  • 2022-12-23
  • 2021-07-04
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-10-18
  • 2022-12-23
  • 2021-05-30
  • 2021-06-05
  • 2021-06-01
  • 2021-06-09
相关资源
相似解决方案