具有多个主类的Gradle应用程序插件 [英] Gradle application plugin with multiple main classes
本文介绍了具有多个主类的Gradle应用程序插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用gradle应用程序"插件启动我的应用程序.这很好. 现在,我想添加选项以在同一项目中启动另一个主类.我可以更改插件的配置以允许吗?
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"
推荐答案
来自 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可以命名为任意名称
- 适当设置main
- 清除不需要的args和systemProperty
要运行:
gradle runSimple
您可以将任意数量的文件放入build.gradle文件中.
You can put as many of these as you like into your build.gradle file.
这篇关于具有多个主类的Gradle应用程序插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文