rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

COURSIER_OPTS env var does not work (with fix)

Open peakschris opened this issue 1 year ago • 3 comments

The COURSIER_OPTS envvar does not work, because it is too early in the command line to be passed to coursier. I'm not sure how to submit a fix to this repository, but am attaching a patch file - could someone please consider including this fix?

Thanks!

rules_jvm_external.patch

peakschris avatar Apr 09 '23 09:04 peakschris

index a71507a..e8b93bb 100644
--- coursier.bzl
+++ coursier.bzl
@@ -239,18 +239,16 @@ def _java_path(repository_ctx):
 # Generate the base `coursier` command depending on the OS, JAVA_HOME or the
 # location of `java`.
 def _generate_java_jar_command(repository_ctx, jar_path):
-    coursier_opts = repository_ctx.os.environ.get("COURSIER_OPTS", "")
-    coursier_opts = coursier_opts.split(" ") if len(coursier_opts) > 0 else []
     java_path = _java_path(repository_ctx)
 
     if java_path != None:
         # https://github.com/coursier/coursier/blob/master/doc/FORMER-README.md#how-can-the-launcher-be-run-on-windows-or-manually-with-the-java-program
         # The -noverify option seems to be required after the proguarding step
         # of the main JAR of coursier.
-        cmd = [java_path, "-noverify", "-jar"] + coursier_opts + _get_java_proxy_args(repository_ctx) + [jar_path]
+        cmd = [java_path, "-noverify"] + ["-jar"] + _get_java_proxy_args(repository_ctx) + [jar_path]
     else:
         # Try to execute coursier directly
-        cmd = [jar_path] + coursier_opts + ["-J%s" % arg for arg in _get_java_proxy_args(repository_ctx)]
+        cmd = [jar_path] + ["-J%s" % arg for arg in _get_java_proxy_args(repository_ctx)]
 
     return cmd
 
@@ -705,6 +703,10 @@ def make_coursier_dep_tree(
         # https://github.com/coursier/coursier/blob/1cbbf39b88ee88944a8d892789680cdb15be4714/modules/paths/src/main/java/coursier/paths/CoursierPaths.java#L29-L56
         environment = {"COURSIER_CACHE": str(repository_ctx.path(coursier_cache_location))}
 
+    coursier_opts = repository_ctx.os.environ.get("COURSIER_OPTS", "")
+    coursier_opts = coursier_opts.split(" ") if len(coursier_opts) > 0 else []
+    cmd.extend(coursier_opts)
+
     # If we are using Java 9 or higher we can use an argsfile to avoid command line length limits
     java_path = _java_path(repository_ctx)
     if java_path:

peakschris avatar Apr 09 '23 09:04 peakschris

The COURSIER_OPTS env var is currently intended to pass JVM args to the coursier command https://github.com/bazelbuild/rules_jvm_external#provide-jvm-options-for-coursier-with-coursier_opts so I think it's in the correct place.

What options are you trying to use with COURSIER_OPTS that are not working?

cheister avatar Jun 05 '23 06:06 cheister

Hi there, sorry for the delay. I am trying to pass --pom-property osgi.platform=win32.win32.x86_64 to the coursier command, as a workaround to this coursier issue: https://github.com/coursier/coursier/issues/2571

I've set up a reproducer for this problem and the patch here: https://github.com/peakschris/bazel-rules-jvm-external-issue

Maybe two separate variables are needed if we need control both over JVM opts and coursier opts?

peakschris avatar May 17 '24 14:05 peakschris