In the first version of the script, I was using Ant Contrib’s foreach task to loop through all JS files in the project then pass these off to another task which would call the compiler. It seems that Ant creates a new classloader as each iteration of the loop calls the compression task. So, as the number of items to be iterated over increases, so does the memory usage.
I got to about 17 files before it failed on me.
The Ant Contrib for task solves this by using the same classloader for each iteration, so you don’t get a memory leak.
So, our updated build task looks like this:
It was pointed out to me that there were a couple of issues with the original script. I’ve updated above as follows:
- I’ve added in the full file path in live 32 as the old script would save the compressed file in its running directory.
- In the same line, I’ve added the option to force compression of the file. When running using TeamCity, the script was ignoring the JS files without this in place.