System.console null in a gradle java task

I am invoking my main class like this from a gradle file and when I am trying to read the password using System.console I am getting a 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 is coming as null in java main class. But I am able to read the password directly from the gradle file.
What am I doing wrong ?

gradle version 2.2
java version : 1.7.0_13

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.html

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

1 Like

Thanks luke , I have a doubt though ,System.out.println("") is printing correctly to the console. How is this possible? Also do you think this can be a good addition to the featureset ?

I have a doubt though ,System.out.println("") is printing correctly to the console. How is this possible?

It’s using the same file descriptor, but that’s not the same as actually inheriting it and being attached to the console. That is, it’s the same stream, but this is not enough for the child process to be able to actually use the console. To the child process, it appears as though stdin is something else like a file.

Also do you think this can be a good addition to the featureset ?

Yes, it should be possible to properly inherit the streams.

Could you please help me to report this as a bug in the gradle jira.

Thnks. Could you please guide me on how to report this as a bug in the gradle jira.I have the jira link and an account but I am not allowed to create bugs I guess.

Done: https://issues.gradle.org/browse/GRADLE-3292