为Grails 加上打包自定义排除文件功能。
当你使用Grails开发时,总是要不停的打包、部署、测试、调整。这样的过程不断重复。
但Grails war命令打包出来的war总是太大,而且很多webapp目录中一些静态文件,测试文件什么的都会打包进war。
现手工给War.groovy脚本中加入打包自定义排除文件功能。
首先确定你是Grails1.1版本,然后在你的GRails安装目录,找到scripts目录,打开_GrailsWar.groovy文件。
在237行左右,加入一下代码(注释中的是加入的代码,以外的是为了方便大家定位)。
// ========= modify by romejiang start ================
//ant.delete(dir:"${stagingDir}/", failonerror:true)
if(config.war.exclude.files)
config.war.exclude.files.each{
Ant.delete(
file:"${stagingDir}/${it}")
}
if(config.war.exclude.dirs)
config.war.exclude.dirs.each{
ant.delete(dir:"${stagingDir}/${it}", failonerror:true)
}
// ========= modify by romejiang end ================
warPlugins()
createDescriptor()
event("CreateWarStart", [warName, stagingDir])
ant.jar(destfile:warName, basedir:stagingDir)
event("CreateWarEnd", [warName, stagingDir])
然后在你的项目的config.groovy中就可以如下定义排除文件了。
// war exclude file and dirs
war {
exclude.files = [
"index.html",
"reference.html"
]
exclude.dirs = [
"projects",
"categorys"
]
}
Groovy&Grails 非常灵活,只有你想不到,没有做不到。
good luck...
为Grails 加上打包自定义排除文件功能。
最新推荐文章于 2023-09-15 09:48:51 发布