简体   繁体   中英

Gradle 'application' plugin - is it possible to specify which mainClassName to use?

I want to be able to choose which main class I run using gradle at the command line using the application plugin.

For example, suppose I have two adjacent apps under /src .

I simply want to run gradle run firstApp or gradle run secondApp and have the mainClassName be specified by the tasks:

task firstApp {
  mainClassName = 'com.example.firstApp'
}

task secondApp {
  mainClassName = 'com.example.secondApp'
}

Is this possible? Unfortunately, it always defaults to the secondApp in this configuration. I am sure I am doing silly gradle mistakes.

Try this:

task firstApp(type:JavaExec) {
  classpath = sourceSets.main.runtimeClasspath
  main = 'com.example.firstApp'
}

task secondApp(type:JavaExec) {
  classpath = sourceSets.main.runtimeClasspath
  main = 'com.example.secondApp'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM