Gradle application plugin with multiple main classes

gradle, java

Solution

From http://mrhaki.blogspot.com/2010/09/gradle-goodness-run-java-application.html

apply plugin: 'java'

task(runSimple, dependsOn: 'classes', type: JavaExec) {
   main = 'com.mrhaki.java.Simple'
   classpath = sourceSets.main.runtimeClasspath
   args 'mrhaki'
   systemProperty 'simple.message', 'Hello '
}

Clearly then what you can change:

- runSimple can be named whatever you want

- set main as appropriate

- clear out args and systemProperty if not needed

To run:

gradle runSimple

You can put as many of these as you like into your build.gradle file.

Problem

I'm using the gradle 'application' plugin to start my application. This works well. Now I want to add the option to start a different main class in the same project. Can I change the plugin's configuration to allow that? ``` apply plugin: 'application' mainClassName = "net.worcade.my.MainClass" ```

Original source

Related problems