如何使用Gradle将参数传递给main方法?

Xelian :

我必须将两个参数传递给我的main方法。我的构建脚本是

// Apply the java plugin to add support for Java
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'maven central' for resolving your dependencies.
    mavenCentral()
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile 'com.example:example-core:1.7.6'
}

task main(type: JavaExec, dependsOn: classes) {
    description = 'This task will start the main class of the example project'
    group = 'Example'
    main = 'com.example.core.Example'
    classpath = sourceSets.main.runtimeClasspath

}

如果我尝试:

gradlew main doc.json text.txt

然后发生错误。

org.gradle.execution.TaskSelectionException: Task 'doc.json' not found in root project

如何轻松地将参数传递给主方法命令行?

埃里克·普拉格特(Erik Pragt):

您应该使用Gradle 命令行文档中列出的use -P

例如,以下将起作用:

gradlew main -Parg1=doc.json --project-prop arg2=text.txt

您可以像这样在Gradle脚本中访问它们:

println "$arg1 $arg2"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将通用参数传递给使用对象的方法?

如何使用GET方法将GET参数传递给Laravel?

如何使用“ #selector”将参数传递给方法

如何使用 | 将多个参数传递给 Ruby 方法?

将参数传递给Main()

将 main 方法中定义的参数传递给实例方法?

将驱动程序参数传递给main之外的方法

如何动态地将命令行参数传递给main方法

让PowerShell脚本使用C#代码,然后将参数传递给Main方法

使用Eclipse将参数传递给C中的main

如何使用Xcode 5中的编辑方案将参数传递给main.cpp

如何从IntelliJ IDEA将参数传递给Gradle

如何使用可变参数将任意数量的相同类型参数传递给方法?

将参数传递给方法

将参数传递给方法

gradle将参数传递给dependsOn任务

将参数传递给build.gradle

如何将参数传递给方法[]的方法定义?

Java:如何使用 lambda 表达式将参数传递给 Thread 方法?

如何使用JEE7 Websockets将参数传递给@OnOpen方法,

如何使用参数将非常数变量值传递给方法?

如何使用Java脚本window.location将参数传递给Play框架中的Java方法?

如何将Java空参数传递给使用JNA编译为C代码的本机方法?

如何使用tkinter将变量作为参数传递给python中的方法

如何将String参数传递给void方法?

如何将方法引用传递给协变参数

如何将参数传递给模拟类方法?

Java:如何将动态数量的参数传递给方法

如何将参数传递给Express post HTTP方法?