Gradle任务 - 将参数传递给Java应用程序 [英] Gradle task - pass arguments to Java application

查看:649
本文介绍了Gradle任务 - 将参数传递给Java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行自定义gradle任务的Java应用程序,应用程序在调用时需要一些参数。它们是:
$ b $ pre $ 程序名(字符串| -f文件名| -d键| -h)
选项:
字符串要使用的消息。
-d key使用默认消息,密钥必须是s [hort],m [edium]或l [ong]。
-f filename使用指定的文件作为输入。
-h帮助对话框。

Gradle任务如下所示:

<$ p $
main ='main.Test'
classpath = sourceSets.main.runtimeClasspath $ task run(type:JavaExec){
description =Secure algorythm testing b $ b}

我试过运行 gradle run -h

解决方案

很抱歉回答这么晚。



我对@xlm提出了同样的答案:

 任务运行(类型:JavaExec,dependsOn :类){
if(project.hasProperty('myargs')){
args(myargs.split(','))
}
description =安全algorythm测试
main =main.Test
classpath = sourceSets.main.runtimeClasspath
}

然后调用:

  gradle run -Pmyargs = -d,s 

code>


I have a Java application that runs with a custom gradle task and the application requires some arguments upon being invoked. These are:

programName ( string | -f filename | -d key | -h)
Options:
    string         Message to be used.
    -d key         Use default messages, key must be s[hort], m[edium] or l[ong].
    -f filename    Use specified file as input.
    -h             Help dialog.

Gradle task looks like:

task run (type: JavaExec){
    description = "Secure algorythm testing"
    main = 'main.Test'
    classpath = sourceSets.main.runtimeClasspath
}

I've tried running gradle run -h and it does not work.

解决方案

Sorry for answering so late.

I figured an answer alike to @xlm 's:

task run (type: JavaExec, dependsOn: classes){
    if(project.hasProperty('myargs')){
        args(myargs.split(','))
    }
    description = "Secure algorythm testing"
    main = "main.Test"
    classpath = sourceSets.main.runtimeClasspath
}

And invoke like:

gradle run -Pmyargs=-d,s

这篇关于Gradle任务 - 将参数传递给Java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆