rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

maven_install unusable on Windows due to hashbang in coursier executable

Open kalmard0 opened this issue 3 years ago • 7 comments

Trying to use a simple maven_install rule on windows (which works fine on mac) results in the following error:

activity depends on @maven//:com_google_android_gms_play_services_nearby in repository @maven which failed to fetch. no such package '@maven//': Unable to run coursier: java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\kalma\_bazel_kalma\waikar5b\external\maven\coursier"): %1 is not a valid Win32 application. (error: 193)

This problem is obvious if you open the coursier binary it points to, as it is actually wrapped in a shell script, and starts with: #!/usr/bin/env sh nargs=$#

Obviously on Windows this is not supported as a standard executable. I tried using different versions of rules_jvm_external and bazel itself to see if perhaps it worked historically, but it doesn't seem so.

kalmard0 avatar Oct 11 '20 09:10 kalmard0

What versions of rules_jvm_external have you tried?

jin avatar Oct 12 '20 07:10 jin

The current HEAD, and basically every release going back to 1.3 or so.

kalmard0 avatar Oct 12 '20 17:10 kalmard0

I was running into the same issue but in my case it turned out I forgot to install Java 8 on the machine: https://docs.bazel.build/versions/master/tutorial/java.html. The error message is a bit deceiving.

tomdegoede avatar Nov 11 '20 10:11 tomdegoede

I'm a bit confused as https://docs.bazel.build/versions/master/install-windows.html actually mentions Java 11.

tomdegoede avatar Nov 11 '20 10:11 tomdegoede

I just want to +1 this issue.

andrewkatson avatar May 10 '21 13:05 andrewkatson

I don't think the hashbang is an issue anymore (Bazel 3.7.1/rules_jvm_external 2.9). I hit this too, but found I had a config problem. Here are some pointers:

  1. Make sure you are setting your JAVA_HOME using Windows Settings and not just exporting it in Git Bash. This was my problem.
  2. Add more debug output to your local {output_base}\external\rules_jvm_external\coursier.bzl file to figure out what case you are falling into in the generate_java_jar_command
  3. Double check that the JDK path that is resolved in generate_java_jar_command is actually correct.

plaird-alt avatar May 22 '21 07:05 plaird-alt

Thank you that totally worked!

andrewkatson avatar May 28 '21 17:05 andrewkatson