Gradle: Using expand and jQuery

During the last days I started to enable a build-time setup for one of my Spring projects.

One thing I set at build time was the spring.profiles.default  context parameter. For replacing wildcards during build time I added the expand()  closure to the war-task of my Gradle build script.

The problem

This works fine til I wanted to add some access to the webservice the tool provided using jQuery. After adding the jQuery library the build fails with the following message

When starting the build with –stacktrace again, I figured out, that the problem was, that the underlying Groovy implementation expects that, when expand is used after a ‘$’ sign a character or a ‘{‘ follows. jQuery has many ‘$’ signs, so a workaround is required.

My solution

Due to the fact, that expand() works in Gradle on every file on a Copy tasks, for example, and didn’t support single file expansion, I started to investigate how to workaround this issue.

I added two new tasks, one for copying the files, which needs to be replaced and the other for the javascript libraries.

The last things I need to do were

  • changing the webAppDirName to ”$buildDir/webapp”
  • setting the webAppDirName of the jetty task
  • let war and jettyRun depending on the expandForWebApp task

Summarized I did the following changes:


Even if I think, that the missing possibility for expanding a single file directly is a little drawback withGradle, I’m very happy that Gradle provides me the possibilities to express the things I would like to do directly in the build script.

2 Kudos

One thought on “Gradle: Using expand and jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *