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"
gradle for one project? Yes. You can have multiple build files in one project.
You can run gradle installDist to create an image of the application in build/install/projectName . You can run gradle distZip to create a ZIP containing the distribution, gradle distTar to create an application TAR or gradle assemble to build both.
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:
To run:
gradle runSimple
You can put as many of these as you like into your build.gradle file.
You can directly configure the Application Plugin with properties:
application {
mainClassName = project.findProperty("chooseMain").toString()
}
And after in command line you can pass the name of the main class:
./gradlew run -PchooseMain=net.worcade.my.MainClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With