这是我的Groovy应用程序的驱动程序类:
package org.me.myapp
class MyDriver {
static void main(String[] args) {
// The p flag was passed in and had a value of 50!
println String.format("The %s flag was passed in and had a value of %s!", args[0], args[1])
}
}
我正在尝试扩充我的Gradle构建,以便我可以:
理想情况下,我可以通过以下方式运行我的应用程序:
gradle run -p 50
请参阅以下控制台输出:
The p flag was passed in and had a value of 50!
这是我的build.gradle
:
apply plugin: 'groovy'
apply plugin: 'eclipse'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
repositories {
mavenCentral()
}
dependencies {
compile (
'org.codehaus.groovy:groovy-all:2.3.9',
'com.google.guava:guava:18.0',
'com.google.inject:guice:3.0'
)
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
我需要做些什么才能让Gradle包+像这样运行我的应用程序?
答案 0 :(得分:2)
要执行run
任务,您需要应用application
插件。您可以将以下代码段添加到build.gradle
apply plugin: 'application'
mainClassName = "org.me.myapp.MyDriver"
run {
args "p"
args "50"
}
您可以使用某些gradle属性名称替换"p"
和"50"
,并从命令行传递这些属性,如
gradle run -Pkey=p -Pvalue=50