Rename GSP in WAR task

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.exclude('index.gsp')
        rootSpec.rename('index-prod.gsp', 'index.gsp')
    }

    rootSpec.exclude('wp-architect/**/.*/**')
    rootSpec.exclude('wp-architect/app-*/**')
    rootSpec.exclude('wp-architect/packages/**')
//    rootSpec.include('wp-architect/build/production/**')
    rootSpec.exclude('wp-architect/build/development/**')
    rootSpec.exclude('wp-architect/build/testing/**')
    rootSpec.exclude('wp-architect/build/temp/**')
    rootSpec.exclude('wp-architect/library/ext/**')
    rootSpec.exclude('wp-architect/library/joose/**')
    rootSpec.exclude('wp-architect/library/siesta-standard/**')

}

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

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.

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
:wp-architect-java:compileWebappGroovyPages
:wp-architect-java:compileGroovyPages
:wp-architect-java:war

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

compileWebappGroovyPages {
    println('compileWebappGroovyPages')
    doFirst {
        file('/grails-app/views/index-prod.gsp').renameTo('AAA.gsp')
    }
}

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.

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.

Eg:

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:

src/dev/webapp/index.gsp
src/sit/webapp/index.gsp
src/prod/webapp/index.gsp

etc