I have Grails plugin that do some job (precompiles static files) at build time (before war is built). To do its job some jar dependencies are required. So this dependencies are required only at build time. How can I exclude them from final WAR?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Add to your BuildConfig.groovy
:
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/whatever.jar")
}
回答2:
This is best done using script. I had to employ this when deploying a WAR for a production that required excluding jar files.
Create a script file called _Event.groovy under the script directory. Inside the _Event.groovy file, add code to delete jar. BTW, this is event triggered and naming convention has to be followed.
In scripts/_Event.groovy
eventCreateWarStart = { warName, myDir ->
println 'EVENT CALLED!'
File libDir = new File("${myDir}/WEB-INF/lib/")
if (grailsEnv != "development") {
libDir.eachFileMatch( ~/^(tomcat|grails-plugin-tomcat).*\.jar$/) { File jarToRemove ->
println 'REMOVING JAR: ' + jarToRemove
jarToRemove.delete()
}
}
}