How can I exclude plugins jar required at build ti

2020-07-23 06:20发布

问题:

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()
      }
   }
}