How can I get localized property values in a gradle build file?

I want to generate some localized html files as part of my build and deployment. As a simple test, I tried this task

task i18n(description:“i18n test”) << {

def locales = [Locale.ENGLISH, Locale.JAPANESE, Locale.GERMAN]

def keys = [ “s1”, “s2”, “s3” ]

[locales, keys].combinations().each{ locale, key ->

def labels = ResourceBundle.getBundle(‘html’, locale)

println “Locale = ${locale.toString()}, key = $key, value = ${labels.getString(key)}”

} }

But it says Can’t find bundle for base name html, locale en_US. I put the resource bundles in the same directory as the build.gradle file (html.properties, html_en.properties, etc). However, it seems that gradle does not try to load the resource bundles from that directory, but rather tries to get them from the gradle classLoader. I’m not sure where that might be, but it is probably outside of source control. Is there a convenient way to get localized messages from property files from within the gradle build script?

The simplest way would be to properties files in ‘buildSrc/src/main/resources’. This will put these files on the classpath for the build execution.

See http://www.gradle.org/docs/current/userguide/organizing_build_logic.html for more details.

Thank you! That worked. It took me a little while to realize that the resources had to go in the buildSrc/main directory and not the src/main directory (which I call “source” in my multi-project). I would prefer if I could have the resources be in the buildSrc directory of the subproject in which they are used instead of the top level, but it does not look like there is a way to do that.