Running a Single Class From Gradle

Whew… been learning a lot about gradle this evening, and I definitely like it. I’ll expand further with an in depth example, but for now just wanted to post a quick solution to something I was attempting to do. See, I wanted to be able to just type gradle run and have it run a single class from my project, but for some reason was having a difficult time figuring out how to make it work.

Luckily, gradle includes practically all the ant tasks so you can simply use ant.java:

task run(dependsOn:'build') <<{
        ant.java(classname: 'org.jamescarr.Main', fork: true,
        classpath: "${sourceSets.main.runtimeClasspath.asPath}")
}

We want it to depend on the build task so it will compile our classes and dependencies, then it'll work as expected. :)

You can leave a response, or trackback from your own site.

Facebook comments:

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!