How to make functions available to submodules?

I’ve started implementing our project’s build in gradle at about version 1.7 or so. I have upgraded so far through the versions and have appreciated not needing to tweak anything much during upgrades. However, I’ve recently upgraded to 1.12 (and am looking at 2.0-rc2), and having difficulty figuring out how to define helper functions and make them available to submodules.

Previously, I had just thrown a bunch of utility functions into the top-level build.gradle. All the build.gradle files in the submodules were able to call these methods with no problem. I was even able to call them from custom plugins in our ‘buildSrc’ folder (e.g. ‘project.isWindows()’).

However, beginning with 1.12, these functions were no longer found in any of my submodules. I have tried defining them as closures underneath ‘allprojects { ext { … } }’, but that appears not work exactly as I had thought, perhaps due to some state captured at the instantiation of the closure (?). I see that using methods to refactor out common build code is a recommended practice (User’s Guide, section 59.1), and the docs say explicitly that “Any method or property defined in a project build script is also visible to all the sub-projects”

Am I missing something? Is this a regression in 1.12?

This is indeed a regression in 1.12, fixed in 2.0.

It’s listed at the bottom of http://www.gradle.org/docs/current/release-notes#known-issues.

Ah, excellent. Didn’t find that when looking for it! Strange that I thought I’d seen this fail before in 2.0-rc2 in the same way, but just ran another test and it appears to be working again on 2.0.

Thanks for the pointer…and for the fix!