I've been exposing to Gradle for a couple of weeks and really like it. As a Maven user, I found that Gradle is a refreshing methodology on how a build tool should be. But one thing I miss from the Maven land: the ability to generate the initial structure for a project (I mean the 'archetype' plugin of Maven). Luckily, due to the plugin architecture of Gradle, a Gradle user has developed a plugin just for that purpose. It's called the 'tempaltes' plugin. The wiki page of the plugin gives you all the details you need to install, but the global installation section is confusing and did not work. Here is how I did to make it work:
  • Create a file called templates.gradle in the ~/.gradle/init.d/ folder (actually you can name it whatever you want as long as it has the extension .gradle)
  • Edit that file and paste this little code snippet:
gradle.beforeProject { prj ->
   prj.apply from: 'http://launchpad.net/gradle-templates/trunk/latest/+download/apply.groovy'
}
Now, you can create a project structure event without a build.gradle with the command:
gradle createJavaProject
Happy coding!

2 comments:

Unknown on January 4, 2013 at 2:40 AM

New to gradle and having problems getting what you listed in your article to work as well as what what in the original wiki.

Tried adding the file templates.gradle to my ~/.gradle/init.d directory. I copied the templates-1.2.jar to my gradle/lib/plugin directory, but nothing works. If I create a build.gradle file and add apply plugin: 'templates' it tells me it can't find the plugin id.

What am I missing?

Anonymous on August 20, 2013 at 4:26 PM

Nice, works flawlessly. Thank you man !

Post a Comment