Gradle 2.6 — How to set the “Main” class to run using the Application plugin

I had been using an older version of Gradle and when I needed to specify my main class to run I added something similar to the lines below to my build.gradle file.

task run(dependsOn:'build') <<{ 'com.gesker.MyMainClass', fork: true,
classpath: "${sourceSets.main.runtimeClasspath.asPath}")

However, the Application plugin in newer versions of Gradle makes this much cleaner. Just add two lines similar to those below to your build.gradle file:

apply plugin: 'application'
mainClassName = "com.gesker.MyMainClass"

By main class I of course mean the specific class you want to run that contains the ever necessary:

public static void main(String args[]) {
// Your Code Here

The above is another great reason to revisit the docs for projects upon which you depend as you upgrade.