Gradle application plugin with multiple main classes

前端 未结 4 1382
南方客
南方客 2021-02-20 04:55

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 ch

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-20 05:04

    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.

提交回复
热议问题