Rename GSP in WAR task

(Mike Suiter) #1

In my war task I need to rename index-prod.gsp to index.gsp which is working. The problem is when I browse to the page I get the old index.gsp and that’s because of the compiled page classes in web-inf/classes. How can I do the rename so the compiled classes reflect this? Here is what I currently have which doesn’t do that.

war {
    archiveName 'wp-architect-java.war'

    doFirst {
        rootSpec.rename('index-prod.gsp', 'index.gsp')

//    rootSpec.include('wp-architect/build/production/**')


Also any tips on how to clean up the rootSpec.exclude(…) so I don’t have to do the entire statement for every line?

(Lance Java) #2

Are you pre-compiling your gsp files into classes as part of the build process?
If so, you’ll need to rename the file before it goes through the gsp compiler.

If not, it’s likely a dirty deploy issue where you’re not cleaning the webapp directory before the deploy hence old files are lying around.

(Mike Suiter) #3

My guess is compileWebappGroovyPages is pre-compiling them.

:wp-architect-java:assetCompile UP-TO-DATE
:wp-architect-java:compileJava UP-TO-DATE
:wp-architect-java:compileGroovy UP-TO-DATE
:wp-architect-java:buildProperties UP-TO-DATE
:wp-architect-java:processResources UP-TO-DATE
:wp-architect-java:classes UP-TO-DATE

I’ve been playing around with this but no luck. I only want to do the rename for a production build.

compileWebappGroovyPages {
    doFirst {

This is a Grails app I’ve converted from Grails 2 to Grails 3 so I’m just starting to learn Gradle. So far it’s been an adventure.

(Lance Java) #4

Warning: I’m not a grails user

Are you trying to rename files which are checked in to source control as part of your build?
That sounds like a really bad idea to me. If it were me… I’d use a flavour style approach similar to android where each flavour has the option to add custom files on top of a set of common files (no renaming is required)

Unfortunately, GroovyPageCompileTask only accepts a single directory. If it were me, I’d copy from two directories to create the source for the GroovyPageCompileTask.


def flavour = 'prod' // possibly passed from command line?
task createGroovyPageCompileSource(type: Copy) {
   from 'src/main/webapp'
   from 'src/${flavour}/webapp'
   into '$buildDir/groovyPages'

compileWebappGroovyPages {
   dependsOn createGroovyPageCompileSource
   source = '$buildDir/groovyPages'

Then you could have a file per flavour eg: