apply plugin: 'java' apply plugin: 'war' apply plugin: 'eclipse-wtp' test { /* // set heap size for the test JVM(s) minHeapSize = "128m" maxHeapSize = "1024m" // show standard out and standard error of the test JVM(s) on the console testLogging.showStandardStreams = true // set JVM arguments for the test JVM(s) jvmArgs '-XX:MaxPermSize=512m' // listen to events in the test execution lifecycle beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } // listen to standard out and standard error of the test JVM(s) onOutput { descriptor, event -> logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message ) } ignoreFailures = true //use this to allow build to continue for CI purposes if (System.getProperty('DEBUG', 'false') == 'true') { jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009' } */ //ignoreFailures = true //use this to allow build to continue for CI purposes //useTestNG() //{ // suites 'src/test/resources/test/forgon/AllTests.xml' //} // enable TestNG support (default is JUnit) useTestNG(){ //outputDirectory = file("$project.buildDir//testngOutput") //report generation delegated to TestNG library: useDefaultListeners = true suites 'src/test/resources/test/forgon/AllTests.xml' } //reports.html.enabled = false ignoreFailures = true //use this to allow build to continue for CI purposes //{ // suites 'src/test/resources/test/forgon/AllTests.xml' //} // set a system property for the test JVM(s) // 设置文件编码为UTF-8,基础数据准备的json文件中有中文 systemProperty "file.encoding", "utf-8" // explicitly include or exclude tests include 'test/forgon/**' //exclude 'org/boo/**' // show standard out and standard error of the test JVM(s) on the console testLogging.showStandardStreams = true // set heap size for the test JVM(s) minHeapSize = "128m" maxHeapSize = "2048m" // set JVM arguments for the test JVM(s) jvmArgs '-XX:MaxPermSize=512m -XX:MaxNewSize=512m' // listen to events in the test execution lifecycle beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } // listen to standard out and standard error of the test JVM(s) onOutput { descriptor, event -> logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message ) } } /* tasks.withType(Test) { testLogging { // set options for log level LIFECYCLE events "passed", "skipped", "failed", "standardOut" showExceptions true exceptionFormat "full" showCauses true showStackTraces true // set options for log level DEBUG and INFO debug { events "started", "passed", "skipped", "failed", "standardOut", "standardError" exceptionFormat "full" } info.events = debug.events info.exceptionFormat = debug.exceptionFormat afterSuite { desc, result -> if (!desc.parent) { // will match the outermost suite def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" def startItem = '| ', endItem = ' |' def repeatLength = startItem.length() + output.length() + endItem.length() println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength)) } } } }*/ apply plugin: 'rebel' buildscript { repositories { mavenCentral() } dependencies { classpath group: 'org.zeroturnaround', name: 'gradle-jrebel-plugin', version: '1.1.2' } } sourceSets { main { resources { // 排除spring security配置的备份文件 exclude 'spring/security/*.back' // 遍历src/main/resources/spring/projects文件夹,如果不是本项目的文件夹,则添加exclude命令 new File(webProjectDir + "/src/main/resources/spring/projects").eachDir{ if (it.name != projectName){ exclude 'spring/projects/' + it.name + '/**' } } // 遍历src/main/resources/config文件夹,如果不是本项目的文件夹,则添加exclude命令 new File(webProjectDir + "/src/main/resources/config").eachDir{ if (it.name != projectName){ exclude 'config/' + it.name + '/**' } } } } } ext.webAppClassesDir = "../ssts-web/src/main/webapp/WEB-INF/classes" configurations { // other configurations e.g. - providedCompile.exclude module: 'commons-logging' all*.transitive = false } // 1. Get dependencies from Maven local repository // 2. Get dependencies from Maven central repository repositories { ivy { // URL can refer to a local directory url "../localrepo/" } mavenLocal() mavenCentral() jcenter() } //Project dependencies dependencies { runtime 'org.apache.neethi:neethi:3.0.2' runtime 'jackson:jackson-all:1.9.11' runtime 'org.quartz-scheduler:quartz:2.2.1' //runtime 'com.mchange:c3p0:0.9.2.1' runtime 'com.mchange:c3p0:0.9.5.2' runtime 'com.mchange:mchange-commons-java:0.2.11' runtime 'javax.transaction:jta:1.1' //runtime 'net.sourceforge.jtds:jtds:1.3.1' runtime 'com.microsoft.sqlserver:sqljdbc4:4.0' runtime 'dom4j:dom4j:1.6.1' runtime 'bsh:bsh:2.0b1' runtime 'activation:activation:1.1' runtime 'antlr:antlr:2.7.7' runtime 'net.sf.ezmorph:ezmorph:1.0.4' runtime 'wsdl4j:wsdl4j:1.6.2' runtime 'org.freemarker:freemarker:2.3.16' runtime 'ognl:ognl:3.0.6' runtime 'cglib:cglib:3.2.0' runtime 'cglib:cglib-nodep:3.2.0' runtime 'xom:xom:1.2.5' runtime 'xml:xmlschema-core:2.0.3' runtime 'org.springmodules:spring-modules-validation:0.8' runtime 'commons-attributes:commons-attributes-api:2.1' runtime 'commons-chain:commons-chain:1.1' runtime 'commons-cli:commons-cli:1.0' runtime 'commons-codec:commons-codec:1.3' runtime 'commons-discovery:commons-discovery:0.2' runtime 'commons-el:commons-el:1.0' runtime 'commons-httpclient:commons-httpclient:3.0' runtime 'commons-jxpath:commons-jxpath:1.2' runtime 'commons-validator:commons-validator:1.3.1' runtime 'xalan:xalan:2.5.1' runtime 'org.codehaus.groovy:groovy-all:1.7.5' runtime 'xml-resolver:xml-resolver:1.2' runtime 'xerces:xercesImpl:2.7.1' runtime 'xml-apis:xml-apis:1.0.b2' runtime 'xml:xmlsec:1.5.7' runtime 'org.apache.xmlbeans:xmlbeans:2.5.0' runtime 'org.opensaml:xmltooling:1.3.2' runtime 'woodstox:woodstox-core-asl:4.4.0' runtime 'woodstox:stax2-api:3.1.4' runtime 'org.apache.velocity:velocity:1.6.3' runtime 'org.apache.commons:commons-jci-core:1.1' runtime 'org.apache.commons:commons-jci-fam:1.1' runtime files ('../localrepo/libs/ojdbc6.jar') runtime group: 'fckeditor', name: 'FCKeditor', version:'2.3' } war{ // 排除lib和classes文件夹,因为war命令会把src\main\java和src\main\resources的所有文件打包进war文件 // 如果不排除,会导致war包内的文件重复 exclude 'WEB-INF/lib/*' exclude 'WEB-INF/classes/**' // 排除各项目的定制文件,本项目需要的文件已经拷贝为web.xml exclude 'WEB-INF/web-*.xml' // 排除webapp/disinfectsystem/config文件夹下非本项目的配置文件 new File(webProjectDir + "/src/main/webapp/disinfectsystem/config").eachDir{ if (it.name != projectName && it.name != 'default'){ exclude 'disinfectsystem/config/' + it.name + '/**' } } } def cleanDir_Method(){ println "运行任务1:cleanDir,删除WEB-INF/lib与WEB-INF/classes文件夹下的所有文件" FileTree tree = fileTree (dir: webAppLibDir); tree.each { File file -> delete(file) } delete webAppClassesDir } def prepareSpringSecurityXmlFile_Method(){ println "运行任务2:准备spring security xml文件,使用标准的或者项目定制的xml文件" // spring security.xml文件名的后缀,applicationContext-acegi-security-standard.xml.back def suffix = 'standard' if (projectName == 'zd5y' || projectName == 'hzszxrmyy' || projectName == 'dysyy' || projectName == 'gdsy'){ suffix = projectName } def springSecurityDir = webProjectDir + "/src/main/resources/spring/security" // 拷贝各项目的applicationContext-acegi-security-standard.xml.back,更名为applicationContext-acegi-security.xml copy { from springSecurityDir + '/applicationContext-acegi-security-' + suffix + ".xml.back" into springSecurityDir rename ('applicationContext-acegi-security-' + suffix + '.xml.back', 'applicationContext-acegi-security.xml') } } def copyToWebappClasses_Method(){ println "运行任务3:copyToWebappClasses:拷贝classes与资源文件到WEB-INF/classes" // 直接拷贝resources文件夹的内容到WEB-INF/classes copy { from webProjectDir + "/src/main/resources" into webAppClassesDir include '**/*.*' } // TODO:需要把classes文件拷贝到WIN-INF/classes下面 copy { from './build/classes/main' into webAppClassesDir include '**/*.*' } } def copyDependenciesToLibDir_Method(){ println "运行任务4:copyDependenciesToLibDir:拷贝依赖jar包到WEB-INF/lib" copy { from configurations.runtime into webAppLibDir exclude { details -> details.file.name.contains('servlet-api') || details.file.name.contains('jsp-api') } //println 'copyDependencies excuted!' } } def prepareWebXmlFile_Method(){ println "运行任务5:prepareWebXmlFile:准备web.xml文件,使用标准的或者项目定制的web.xml文件" // web.xml文件名的后缀 def suffix = 'standard' if (projectName == 'zd5y' || projectName == 'cszxyy'){ suffix = projectName } // 拷贝各项目的web.xml,更名为web.xml copy { from webInfDir + '/web-' + suffix + ".xml" into webInfDir rename ('web-' + suffix + ".xml", 'web.xml') } } task cleanDir0 { cleanDir_Method() } task prepareSpringSecurityXmlFile0 { prepareSpringSecurityXmlFile_Method() } task copyToWebappClasses0 { copyToWebappClasses_Method() } task copyDependenciesToLibDir0 { copyDependenciesToLibDir_Method() } task prepareWebXmlFile0 { prepareWebXmlFile_Method() } // task定义的名字后加上 <<,这样不会每次build都自动运行task,也可改为doLast task cleanDir << { cleanDir_Method() } task prepareSpringSecurityXmlFile << { prepareSpringSecurityXmlFile_Method() } task copyToWebappClasses << { copyToWebappClasses_Method() } task copyDependenciesToLibDir << { copyDependenciesToLibDir_Method() } task prepareWebXmlFile << { prepareWebXmlFile_Method() } prepareSpringSecurityXmlFile.dependsOn cleanDir copyToWebappClasses.dependsOn prepareSpringSecurityXmlFile copyDependenciesToLibDir.dependsOn copyToWebappClasses prepareWebXmlFile.dependsOn copyDependenciesToLibDir // build结束后,自动运行准备web.xml文件的任务,以及该任务所依赖的任务 build.finalizedBy(prepareWebXmlFile) //war.finalizedBy(prepareWebXmlFile)