我正在创建简单的Java类,我想通过使用gradle创建开箱即用的启动器.
所以我希望能够通过gradle运行Java程序:
gradlew clean run These are my command line arguments哪里These are my command line arguments直接传递给我的public static void main(String... args)方法.
我正在使用apply plugin: "application"它给了我run任务.但当我按照'原样'运行时,我得到了:
* What went wrong:
Task 'These' not found in root project 'question1'. Some candidates are: 'test'.
Luk*_*fer 10
Gradle将每个不以hyphen(-)作为任务名称开头的参数解释为定义在构建期间将执行哪些任务.由于名称的任务These不存在,因此构建失败.
您正在使用Gradle应用程序插件,正如您所说,它提供了一项run任务.该文档显示,该run任务的类型JavaExec.因此,要应用您的参数,请run通过args以下方式将它们添加到任务:
run {
args 'These are my command line arguments'
}
Run Code Online (Sandbox Code Playgroud)
要在不更改build.gradle文件的情况下修改每个构建的参数,只需使用项目属性:
run {
args findProperty('runArgs')
}
Run Code Online (Sandbox Code Playgroud)
并致电 gradle clean run -PrunArgs='These are my command line arguments'
| 归档时间: |
|
| 查看次数: |
7099 次 |
| 最近记录: |