Search code examples
grailsmaven-3

Side effects of establishing maven cache path for Grails 2.5.6 applications


Establishing a maven cache path for Grails 2.5.6 applications has many side effects and I don't know if this is a known bug that I couldn't find reported or if I'm doing it wrong.

Our Grails applications (mostly in 2.0.4 version) have a grails.war.resources closure in the buildConfig.groovy that prevents certain static resources from reaching the war. However, for Grails 2.5.6 applications this closure didn't work until we created an empty ${HOME}/.grails/settings.groovy

Yes, empty (surprise 1). This situation happened both in Windows 7 using Eclipse Neon, and in a Red Hat Linux using Jenkins to build the applications.

Once we had this settings.groovy file we decided to use it to establish the maven cache path, so that both Grails and Java applications could share the same cache. The file contained one single line:

grails.dependency.cache.dir="D:/DEV-WAS8/CONF/m2/repository"

With this single line, building Grails 2.0.4 applications generated wars full of garbage because the grails.war.resources closure didn't work (surprise 2). This made no sense, but at least Grails 2.5.6 were built correctly. So we tried to establish the cache path only for 2.5.6 applications. The settings.groovy was the following one:

if (System.getProperty("grails.version")=="2.5.6") {
   grails.dependency.cache.dir="D:/DEV-WAS8/CONF/m2/repository"
}

In this case grails.war.resources closure didn't work for 2.5.6 ones and 2.0.4 ones built correctly (Surprise 3).

grails.dependency.cache.dir being a System property, we established it at operating system level so that the settings.groovy file remained empty. Wars were generated correctly for both 2.5.6 and 2.0.4 but the maven cache path was not established correctly in Windows 7 using Eclipse Neon. However, it worked perfectly in Linux with Jenkins (Surprise 4).

How we solved it

To resolve the situation now we use an empty settings.groovy file and 2.5.6 applications establish the maven cache path in the buildConfig.groovy


Solution

  • The problem was that the grails.war.resources closure inside the buildConfig.groovy file was incorrectly nested within the grails.project.dependency.resolution closure. This, although incorrect, seemed to work in other Grails versions such as 1.3.7 and 2.0.4. However, the closure is not reachable any more in version 2.5.6 when nested. Once unnested it worked and war resources were filtered as expected