Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to build binary package with gradlew.bat on Windows 7 (SP1, 64-bit) #60

Open
vsosnin opened this issue Nov 6, 2014 · 25 comments

Comments

@vsosnin
Copy link

vsosnin commented Nov 6, 2014

C:\tmp\groovyserv-1.0.0>gradlew.bat --stacktrace clean distLocalBin
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
:clean
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:compileGroovy
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileGo
>> Compiling Go sources...
>> Executing command...
$ go build --ldflags -X main.GroovyServVersion 1.0.0 -o C:\tmp\groovyserv-1.0.0\build/platforms/local/groovyclient.exe C:\tmp\groovyserv-1.0.0\src\main\go\cmd\groovyclient\groovyclient.go
Exit for status code 1
:compileGo FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\tmp\groovyserv-1.0.0\build.gradle' line: 359

* What went wrong:
Exit for status code 1 while executing 'go build --ldflags -X main.GroovyServVersion 1.0.0 -o C:\tmp\groovyserv-1.0.0\build/platforms/local/groovyclient.exe C:\
tmp\groovyserv-1.0.0\src\main\go\cmd\groovyclient\groovyclient.go'

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.GradleScriptException: Exit for status code 1 while executing 'go build --ldflags -X main.GroovyServVersion 1.0.0 -o C:\tmp\groovyserv-1.0.0\buil
d/platforms/local/groovyclient.exe C:\tmp\groovyserv-1.0.0\src\main\go\cmd\groovyclient\groovyclient.go'
        at build_2h60c42aqaskb00h6026ls90ik.executeCommand(C:\tmp\groovyserv-1.0.0\build.gradle:359)
        at build_2h60c42aqaskb00h6026ls90ik.executeCommand(C:\tmp\groovyserv-1.0.0\build.gradle)
        at build_2h60c42aqaskb00h6026ls90ik$executeCommand.callCurrent(Unknown Source)
        at build_2h60c42aqaskb00h6026ls90ik.compileGoSrc(C:\tmp\groovyserv-1.0.0\build.gradle:373)
        at build_2h60c42aqaskb00h6026ls90ik$_run_closure10_closure45_closure46.doCall(C:\tmp\groovyserv-1.0.0\build.gradle:170)
        at build_2h60c42aqaskb00h6026ls90ik$_run_closure10_closure45.doCall(C:\tmp\groovyserv-1.0.0\build.gradle:162)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:548)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:529)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:56)


BUILD FAILED

Total time: 9.247 secs
@nobeans
Copy link
Member

nobeans commented Nov 6, 2014

What is the version of go command?

What's happen if you run go command like this:

$ go build --ldflags "-X main.GroovyServVersion 1.0.0" -o C:\tmp\groovyserv-1.0.0\build/platforms/local/groovyclient.exe C:\tmp\groovyserv-1.0.0\src\main\go\cmd\groovyclient\groovyclient.go

BTW, even in Win7/64bit, you can use the bin package which can be download from http://kobo.github.io/groovyserv/download.html.

@vsosnin
Copy link
Author

vsosnin commented Nov 6, 2014

C:\tmp\groovyserv-1.0.0>go version
go version go1.3 windows/amd64

go build --ldflags "-X main.GroovyServVersion 1.0.0" -o C:\tmp\groovyserv-1.0.0\build/platforms/local/groovyclient.exe C:\tmp\groovyserv-1.0.0\src\main\go\cmd\groovyclient\groovyclient.go

worked fine. No errors.

I installed groovyserv with gvm but couldn't run it. That's why I tried building it afterwords. Here's the error:

$ groovyclient -v
ERROR: your platform not supported: windows_amd64
Sorry, please build by yourself. See http://kobo.github.io/groovyserv/howtobuild.html

@nobeans
Copy link
Member

nobeans commented Nov 7, 2014

There are two problems:

  • (1) could not install by setup script
  • (2) could not build by gradle

(1) could not install by setup script

It seems that you run groovyclient which is a copy of setup.sh on Cygwin, NOT groovyclient.bat which is a copy of setup.bat on DOS prompt. Using the current setup.sh, the error is reproduced because it hasn't supported to run on Cygwin.

Try to run the setup.bat on DOS prompt. I think it works well.

BTW, GroovyServ doesn't support Cygwin officially. So, it might be tough to use it on Cygwin even though you installed it successfully. (GroovyServ itself work even on Cygwin but it needs some cares, e.g. converting of cygpath of environment variables like JAVA_HOME.)

Anyway, I'll improve the setup.sh to work even in Windows/64bit.

(2) could not build by gradle

Hmm. I don't know why the go command didn't work well...
I'll write something about it later.

@vsosnin
Copy link
Author

vsosnin commented Nov 7, 2014

Thanks for looking into this.
I attempted to start groovyserver (in cmd console, not cygwin) but it timed out and didn't create a log file even though I specified -v option (%USERPROFILE%.groovy\groovyserv was empty):

C:\cygwin\home\vlad\.gvm\groovyserv\1.0.0\bin>groovyserver.exe -v
Java home directory: C:\Program Files\Java\jdk1.7.0_25
Groovy home directory: C:\Program Files (x86)\Groovy\Groovy-2.1.5
Groovy command path: C:\Program Files (x86)\Groovy\Groovy-2.1.5\bin\groovy.bat (found at GROOVY_HOME)
GroovyServ home directory: C:\cygwin\home\vlad\.gvm\groovyserv\1.0.0
GroovyServ work directory: C:\Users\vlad\.groovy\groovyserv
Original classpath: (none)
GroovyServ default classpath: C:\cygwin\home\vlad\.gvm\groovyserv\1.0.0\lib\*
Starting server......................................................................................
ERROR: timed out while waiting for server startup 

@nobeans
Copy link
Member

nobeans commented Nov 7, 2014

Please run with --debug option:

> groovyserver -v --debug

@vsosnin
Copy link
Author

vsosnin commented Nov 8, 2014

Starting server....'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Looks like it doesn't know how to handle the space in "Program Files"

@vsosnin
Copy link
Author

vsosnin commented Nov 8, 2014

...and also this

2014/11/07 19:57:05.516123 server.go:325: connect: end: (*server.ConnectedServer)(nil)
, &errors.errorString{s:"could not connect to server: dial tcp 127.0.0.1:1961: ConnectEx tcp: No connection could be made because the target machine actively refused it."}
2014/11/07 19:57:05.516123 server.go:81: canConnect: could not connect to server: could not connect to server: dial tcp 127.0.0.1:1961: ConnectEx tcp: No connection could be made because the target machine actively refused it.
2014/11/07 19:57:05.516123 server.go:76: canConnect: end: false

it appears that Windows firewall is blocking connection to port 1961

@nobeans
Copy link
Member

nobeans commented Nov 10, 2014

It seems the value of GROOVY_HOME has a white space. And Groovy can't work with it.
Could you try to run groovyserver without GROOVY_HOME (set GROOVY_HOME=) and with PATH having a path to groovy command?

@nobeans
Copy link
Member

nobeans commented Nov 10, 2014

You can also use the short path syntax like PROGRA~1% that there is no space.

@nobeans
Copy link
Member

nobeans commented Nov 10, 2014

I'm still analyzing this issue...

@nobeans
Copy link
Member

nobeans commented Nov 10, 2014

Could you paste this part of console log of --debug?

server.go:332: startInBackground: command: &exec. Cmd{Path:"C:\\Program Files\\...\\groovy.bat", Args:[]string{"C:\\Program Files\\...\\groovy.bat", "-v", "groovyx.groovyserv. GroovyServer.main(args)", "--", "1961", "xxxx"}, Env: ***SNIPPED***

NOTE: I want to see only Path and Args. The part of Env doesn't have to paste because it may have privacy information.

@vsosnin
Copy link
Author

vsosnin commented Nov 10, 2014

2014/11/07 20:11:04.597116 server.go:313: startInBackground: command: &exec.Cmd{Path:"C:\\Program Files (x86)\\Groovy\\Groovy-2.1.5\\bin\\groovy.bat", Args:[]string{"C:\\Program Files (x86)\\Groovy\\Groovy-2.1.5\\bin\\groovy.bat", "-e", "groovyx.groovyserv.GroovyServer.main(args)", "--", "1961", "", "", "true", "-v"}, Env:[]string{***SNIPPED***}, Dir:"", Stdin:io.Reader(nil), Stdout:(*os.File)(0x1f132098), Stderr:(*os.File)(0x1f1320a0), ExtraFiles: []*os.File(nil), SysProcAttr:(*syscall.SysProcAttr)(nil), Process:(*os.Process)(nil), ProcessState:(*os.ProcessState)(nil), lookPathErr:?reflect.Value?, finished:false, childFiles:[]*os.File(nil), closeAfterStart:[]io.Closer(nil), closeAfterWait:[]io.Closer(nil), goroutine:[]func() error(nil), errch:(chan error)(nil)}
2014/11/07 20:11:04.614117 server.go:249: startInBackground: end: <nil>
Starting server....'C:\Program' is not recognized as an internal or external command, operable program or batch file.
....................................................................................................
2014/11/07 20:11:24.820273 server.go:202: Start: end: timed out while waiting for server startup
ERROR: timed out while waiting for server startup

@nobeans
Copy link
Member

nobeans commented Nov 10, 2014

According to my today's analysis, only in the case of Windows, Go language's Command#Run() would fail both when the arguments have a blank and when the command path has a white-space, for some reason. And it shows the curious path in the error message, which is only the left side of white-space.

I think that there are the workaround:

  • (a) to use the windows short path format like set GROOVY_HOME=C:\\PROGRA ~ 1\\Groovy\\Groovy-2.1.5 having no white-space.
  • (b) to specify both the authtoken and allowFrom address explicitly.

(a) is the easier and better way.

@vsosnin
Copy link
Author

vsosnin commented Nov 10, 2014

I will try with short path format later today. As for (b), is it how to open up the port in Windows firewall (inbound rules)?

@nobeans
Copy link
Member

nobeans commented Nov 11, 2014

Do you concern about this log?

2014/11/11 09:29:30.798923 server.go:81: canConnect: could not connect to server: could not connect to server: dial tcp 127.0.0.1:1961: Conn ectEx tcp: No connection could be made because the target machine actively refused it.

This isn't due to firewall. It just said, "I couldn't connect to server."
In the case that no server process is running and its port isn't opened, the log is also emitted.

So, I think the core problem is the white-space in the command path. (It often causes problem in Windows.)

I will try with short path format later today.

How about the result? something changed?

@vsosnin
Copy link
Author

vsosnin commented Nov 11, 2014

It worked fine after replacing Program Files (x86) with PROGRA~2 in GROOVY_HOME. Served started successfully.

@nobeans
Copy link
Member

nobeans commented Nov 11, 2014

Great! About how to handle the path including white-spaces, it seems a problem of Go language, so far. I've created a ticket: https://code.google.com/p/go/issues/detail?id=9084 . If it wouldn't fix, I'll think a way of handling it in GroovyServ. For the meantime, please do it as the workaround.

BTW, About "(2) could not build by gradle", do you want to solve it?

@vsosnin
Copy link
Author

vsosnin commented Nov 11, 2014

yes, it would be nice to solve gradle build problem too. What do I need to do for that?
Btw, server is rejecting my client connections saying authtoken is invalid even though I use the value copied from %USERPROFILE%/.groovy/groovyserv/authtoken-1961 file:

>groovyclient -Ca 2da9c6f8-b892-4877-87f0-3811b74b9886 -e "println 'Hello, GroovyServ.'"
ERROR: rejected by groovyserv because of invalid authtoken

From the log:

2014/11/11 01:39:14,376 [DEBUG] (java.lang.ThreadGroup[name=main,maxpri=10]) (GroovyServer:110) Accepted socket: Socket[addr=/127.0.0.1,port=61478,localport=1961]
2014/11/11 01:39:14,378 [DEBUG] (GServThreadGroup:61478) (RequestWorker:68) Request worker is started
2014/11/11 01:39:14,382 [DEBUG] (GServThreadGroup:61478) (ClientProtocols:164) Parsed headers: [Cwd:[C:\Users\vlad], AuthToken:[2da9c6f8-b892-4877-87f0-3811b74b9886], Arg:[LWU=, cHJpbnRsbiAnSGVsbG8sIEdyb292eVNlcnYuJw==]]
2014/11/11 01:39:14,384 [ERROR] (GServThreadGroup:61478) (InvocationRequest:42) Authentication failed. AuthToken is unmatched: null <=> ******
2014/11/11 01:39:19,385 [DEBUG] (GServThreadGroup:61478) (RequestWorker:100) Failed to open new session: Authentication failed. AuthToken is unmatched: null <=> ******
groovyx.groovyserv.exception.InvalidAuthTokenException: Authentication failed. AuthToken is unmatched: null <=> ******
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at groovyx.groovyserv.InvocationRequest.check(InvocationRequest.groovy:44)
    at groovyx.groovyserv.InvocationRequest$check.call(Unknown Source)
    at groovyx.groovyserv.ClientProtocols.readInvocationRequest(ClientProtocols.groovy:123)
    at groovyx.groovyserv.ClientProtocols$readInvocationRequest.call(Unknown Source)
    at groovyx.groovyserv.ClientConnection.openSession(ClientConnection.groovy:73)
    at groovyx.groovyserv.ClientConnection$openSession.call(Unknown Source)
    at groovyx.groovyserv.RequestWorker.parseRequest(RequestWorker.groovy:95)
    at groovyx.groovyserv.RequestWorker.run(RequestWorker.groovy:71)
    at java.lang.Thread.run(Thread.java:724)
    (sanitized)
2014/11/11 01:39:19,388 [DEBUG] (GServThreadGroup:61478) (ClientConnection:108) Sent exit status 201 with the message: Authentication failed. AuthToken is unmatched: null <=> ******

@nobeans
Copy link
Member

nobeans commented Nov 11, 2014

About the issue of authtoken, it seems to be used an old groovyclient command.
What does groovyclient -v show?
And confirm using really new groovyclient.

@nobeans
Copy link
Member

nobeans commented Nov 11, 2014

About "(2) could not build by gradle":

  1. Save the following code as "build.gradle" in new empty directory.
  2. Run gradle (with no argument)
// build.gradle
defaultTasks "goVersion", "goBuild"

task goVersion << {
    executeCommand("go version")
}

task goBuild << {
    def srcFile = new File("hello.go")
    def exeFile = new File("hello")
    if (exeFile.exists()) {
        exeFile.delete()
    }
    if (!srcFile.exists()) {
        new File("hello.go") << """\
            |package main
            |func main() {
            |    println("Hello") // print to stderr
            |}
            |""".stripMargin()
    }
    executeCommand("go build hello.go")
    executeCommand("./hello")
}


def executeCommand(String command) {
    println "-" * 50
    def p = command.execute()
    p.consumeProcessOutput(System.out as OutputStream, System.err as OutputStream) // Gradle's wrapper stream writes nothing to console
    int statusCode = p.waitFor()
    println "Out: ${p.in.text}"
    println "Err: ${p.err.text}"
    println "Return: ${statusCode}"
    println "-" * 50
}

Expected:

> gradle
:goVersion
--------------------------------------------------
Out: go version go1.3 windows/386

Err:
Return: 0
--------------------------------------------------
:goBuild
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------
--------------------------------------------------
Out:
Err: Hello

Return: 0
--------------------------------------------------

BUILD SUCCESSFUL

@vsosnin
Copy link
Author

vsosnin commented Nov 12, 2014

About the issue of authtoken, it seems to be used an old groovyclient command.

That was it. After restarting groovyserver client was able to establish the connection.

@vsosnin
Copy link
Author

vsosnin commented Nov 12, 2014

1. Save the following code as "build.gradle" in new empty directory.
2. Run gradle (with no argument)

When running in cygwin console:

$ gradle
:goVersion
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------
:goBuild
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------

BUILD SUCCESSFUL

Total time: 8.913 secs

When running in cmd console:

C:\tmp\gradletest>gradle
:goVersion
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------
:goBuild
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------
--------------------------------------------------
Out:
Err:
Return: 0
--------------------------------------------------

BUILD SUCCESSFUL

Total time: 2.464 secs

For some reason it swallowed stdout and stderr

@vsosnin
Copy link
Author

vsosnin commented Nov 12, 2014

Your executeCommand() method doesn't have StringBuffer for stdout, stderr. Maybe that's what the problem is?

Try this instead:

def executeCommand(cmd, workDir="", userInput="") {
    println "-" * 50
    println('> Executing: '+cmd)
    def sout = new StringBuffer()
    def serr = new StringBuffer()
    def proc
    if(workDir) {
        proc = cmd.execute([], new File(workDir))
    } else {
        proc = cmd.execute()
    }
    proc.consumeProcessOutput(sout, serr)
    if(userInput) {
        proc.withWriter { writer ->
            writer << "${userInput}"
        }
    }
    proc.waitForOrKill(30000)
    def exitValue = proc.exitValue()
    println("   Returned with status: ${exitValue}")    
    if (exitValue) {
        println('ERROR: '+serr)
    } else {
        if(sout) println('   stdout: '+sout)
        if(serr) println('   stderr: '+serr)
    }
    println "-" * 50
}

This will print stdout and stderr correctly:

C:\tmp\gradletest>gradle
:goVersion
--------------------------------------------------
> Executing: go version
   Returned with status: 0
   stdout: go version go1.3 windows/amd64

--------------------------------------------------
:goBuild
--------------------------------------------------
> Executing: go build hello.go
   Returned with status: 0
--------------------------------------------------
--------------------------------------------------
> Executing: ./hello
   Returned with status: 0
   stderr: Hello

--------------------------------------------------

BUILD SUCCESSFUL

Total time: 3.549 secs

@nobeans
Copy link
Member

nobeans commented Nov 12, 2014

Thank you! Thanks to your information, I've found the cause and another problem for debugging!

The cause of the failure of building is a bad configuration only for Windows in build.gradle.
I attempted to use a 386 binary even in windows/amd64 for simplicity formely.
But it wasn't good idea because it means to be used a cross-compilation in Windows/amd64.
And a cross-compilation requires some preparation beforehand.
A general Windows/amd64 user doesn't prepare for it. So, a build is failed.

And a thing to be difficult to analyze the issue is a way of handling System.out/err of a sub process executed from Gradle.
When fixed it, I got this output:

>> Executing command...
$ go build --ldflags -X main. GroovyServVersion 1.0.0 -o C:\tmp\groovyserv\build/platforms/local/groovyclient.exe
C:\tmp\groovyserv\src\main\go\cmd\groovyclient\groovyclient.go
ERROR: go build runtime: windows/386 must be bootstrapped using make.bat

A direct use of System.out/err as follows

p.consumeProcessOutput(System.out as OutputStream, System.err as OutputStream) // Gradle's wrapper stream writes nothing to console

works in Mac and Linux, but it doesn't in Windows. There is no output from a sub process in Windows. So it makes a analysis be difficult.

Now a workaround for you to build is just to comment out the L173 in build.gradle.

        //env += [GOOS: "windows", GOARCH: "386"] // using a '386' binary even in 64-bit Windows

Then, you can build successfully, perhaps.
I'll release the fix and improvement of handling System.out/err of a sub process at next version.

@nobeans
Copy link
Member

nobeans commented Nov 26, 2014

About how to handle the path including white-spaces, it seems a problem of Go language, so far. I've created a ticket: https://code.google.com/p/go/issues/detail?id=9084 . If it wouldn't fix, I'll think a way of handling it in GroovyServ. For the meantime, please do it as the workaround.

The issue has just been closed. But the status is Unfortunate which means Won't fix... https://code.google.com/p/go/issues/detail?id=9084
Alex said that this problem is caused by CMD.exe itself. And that's perhaps truth.

Now, I have to think about a workaround for this problem as GroovyServ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants