gpt4 book ai didi

gradle - Gradle Java任务中的System.console null

转载 作者:行者123 更新时间:2023-12-03 04:04:29 24 4
gpt4 key购买 nike

我正在从gradle文件中调用我的主类,当我尝试使用System.console读取密码时,我得到了NPE。

task (getRepositoryInfo, dependsOn: 'classes', type: JavaExec) {
standardInput = System.in
standardOutput = System.out
environment('TERM', 'dumb')
main = 'com.devpt.explorer.Demo'
mainClassName = 'com.devpt.explorer.Demo'
classpath = sourceSets.main.runtimeClasspath
def stageName = project.hasProperty("STAGE_NAME")? project.getProperty("STAGE_NAME"): "stageXXXX"
def operations = project.hasProperty("OPERATIONS")? project.getProperty("OPERATIONS"): "ALL"
def buildId = project.hasProperty("BUILD_ID")? project.getProperty("BUILD_ID"): "DUMMY"
args operations
args stageName
args buildId
}

System.console在Java主类中为null。但是我能够直接从gradle文件中读取密码。
我究竟做错了什么 ?

代码示例: https://github.com/ajayboseac/GradleExample

gradle 2.2版
Java版本:1.7.0_13

最佳答案

我已经在gradle中发布了问题,并确认控制台应该为空

链接:https://discuss.gradle.org/t/system-console-null-in-a-gradle-java-task/9274

引用答案:

The forked process isn't attached to a console. This is only possible to achieve by using the JDK process builder API with Java 7. Here's an article I found on the topic after a quick search: http://tamanmohamed.blogspot.com.au/2012/06/jdk7-processbuilder-and-how-redirecting.html2

Gradle doesn't yet support inherit streams for forked processes via its JavaExec and Exec tasks.

关于gradle - Gradle Java任务中的System.console null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29798048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com