Index: build.gradle =================================================================== diff -u -r16504 -r16546 --- build.gradle (.../build.gradle) (revision 16504) +++ build.gradle (.../build.gradle) (revision 16546) @@ -32,9 +32,11 @@ ext.struts2Version = '2.3.24.1' ext.cxfVersion = '3.1.5' ext.encoding = 'UTF-8' - ext.webAppLibDir = "../ssts-web/src/main/webapp/WEB-INF/lib" + ext.webInfDir = "../ssts-web/src/main/webapp/WEB-INF" + ext.webAppLibDir = webInfDir + "/lib" // 用ext方式定义变量,以便子项目进行引用 ext.projectName = projectName + ext.webProjectDir = webProjectDir compileJava { sourceCompatibility = jdkversion @@ -830,21 +832,21 @@ compile (project(":ssts-datasync")) compile (project(":ssts-datasync-default-impl")) - - if (projectName == 'gyey'){ + // ssts-web项目,具有条件依赖,根据发布项目的名称,依赖于不同的jar包 + if (projectName == 'gyey'){ // 广医二院 compile (project(":ssts-datasync-settlement-gyey-impl")) } - else if (projectName == 'cszxyy'){ + else if (projectName == 'cszxyy'){ // 长沙中心医院 compile (project(":ssts-cszxyy-misc")) } - else if (projectName == 'zd5y'){ + else if (projectName == 'zd5y'){ // 中大五院 compile (project(":ssts-zd5y-misc")) // 引入CAS client,用户单点登录的身份验证 compile group: 'org.jasig.cas.client', name: 'cas-client-core', version: '3.4.1' // 引入Spring Security CAS的jar包 compile 'org.springframework.security:spring-security-cas:' + springSecurityVersion } - else if (projectName == 'gdsy'){ + else if (projectName == 'gdsy'){ // 广东省人民医院 compile (project(":ssts-gdsy-misc")) } } Index: ssts-web/build.gradle =================================================================== diff -u -r16504 -r16546 --- ssts-web/build.gradle (.../build.gradle) (revision 16504) +++ ssts-web/build.gradle (.../build.gradle) (revision 16546) @@ -34,78 +34,36 @@ sourceSets { main { resources { + // 条件排除spring security配置文件 exclude getExcludeSpringSecurityXmlFilePath() + + // 遍历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" - -war{ - // 排除lib和classes文件夹,因为war命令会把src\main\java和src\main\resources的所有文件打包进war文件 - // 如果不排除,会导致war包内的文件重复 - exclude 'WEB-INF/lib/*' - exclude 'WEB-INF/classes/**' - - } - -// 返回打包时需要排除的sping security xml配置文件的路径 -// 做了单点登录后,中大五院的spring security有自己的xml配置,打包时需要根据项目类型进行选择性的打包 -// 如果是中大五院的项目,Spring Security的XML配置文件,使用在projects\zd5y文件夹下的 -def getExcludeSpringSecurityXmlFilePath() { - println "war cmd 项目名称:" + projectName - if (projectName == 'zd5y'){ - - return 'spring/applicationContext-acegi-security.xml' - } - else{ - return 'spring/projects/zd5y/applicationContext-acegi-security.xml' - } +configurations { + // other configurations e.g. - providedCompile.exclude module: 'commons-logging' + all*.transitive = false } - task cleanDir { - doLast { - - FileTree tree = fileTree (dir: webAppLibDir); - tree.each { File file -> - delete(file) - } - - delete webAppClassesDir - } -} - - -task copyToWebappClasses << { - copy { - from './build/classes/main' - into webAppClassesDir - include '**/*.*' - } - copy { - from './build/resources/main' - into webAppClassesDir - include '**/*.*' - exclude getExcludeSpringSecurityXmlFilePath() - } -} - - -task copyDependenciesToLibDir(type: Copy) { - from configurations.runtime - into webAppLibDir - exclude { details -> details.file.name.contains('servlet-api') || - details.file.name.contains('jsp-api') } - //println 'copyDependencies excuted!' -} - -copyToWebappClasses.dependsOn cleanDir - -copyDependenciesToLibDir.dependsOn copyToWebappClasses - - // 1. Get dependencies from Maven local repository // 2. Get dependencies from Maven central repository repositories { @@ -118,11 +76,6 @@ jcenter() } -configurations { - // other configurations e.g. - providedCompile.exclude module: 'commons-logging' - all*.transitive = false -} - //Project dependencies dependencies { @@ -193,6 +146,98 @@ } +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 + '/**' + } + } + + } +// 返回打包时需要排除的sping security xml配置文件的路径 +// 做了单点登录后,中大五院的spring security有自己的xml配置,打包时需要根据项目类型进行选择性的打包 +// 如果是中大五院的项目,Spring Security的XML配置文件,使用在projects\zd5y文件夹下的 +def getExcludeSpringSecurityXmlFilePath() { + if (projectName == 'zd5y'){ + + return 'spring/applicationContext-acegi-security.xml' + } + else{ + return 'spring/projects/zd5y/applicationContext-acegi-security.xml' + } +} -war.dependsOn copyDependenciesToLibDir \ No newline at end of file + + task cleanDir { + println "运行任务1:cleanDir,删除WEB-INF/lib与WEB-INF/classes文件夹下的所有文件" + FileTree tree = fileTree (dir: webAppLibDir); + tree.each { File file -> + delete(file) + } + + delete webAppClassesDir +} + + +task copyToWebappClasses { + println "运行任务2:copyToWebappClasses:拷贝classes与资源文件到WEB-INF/classes" + copy { + from './build/classes/main' + into webAppClassesDir + include '**/*.*' + } + copy { + from './build/resources/main' + into webAppClassesDir + include '**/*.*' + exclude getExcludeSpringSecurityXmlFilePath() + } +} + + +task copyDependenciesToLibDir() { + println "运行任务3: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!' + } +} + +task prepareWebXmlFile() { + println "运行任务4: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') + } +} + +copyToWebappClasses.dependsOn cleanDir + +copyDependenciesToLibDir.dependsOn copyToWebappClasses + +prepareWebXmlFile.dependsOn copyDependenciesToLibDir + +// build结束后,自动运行准备web.xml文件的任务,以及该任务所依赖的任务 +build.finalizedBy(prepareWebXmlFile) + +//war.dependsOn copyDependenciesToLibDir \ No newline at end of file