Skip to content

Commit

Permalink
Enable parsing COURSIER_OPTS env var to add parameters to coursier in…
Browse files Browse the repository at this point in the history
…vocation (#385)

This enables e.g. increasing available memory settings for couriser (-Xmx).
  • Loading branch information
gergelyfabian committed Feb 24, 2020
1 parent 27f6f3c commit 2a2c079
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ maven_install(
)
```

### Provide JVM options for Coursier with `COURSIER_OPTS`

You can set up `COURSIER_OPTS` environment variable to provide some additional JVM options for Coursier.
This is a space-separated list of options.

Assume you'd like to override Coursier's memory settings:

```bash
COURSIER_OPTS="-Xms1g -Xmx4g"
```

## Exporting and consuming artifacts from external repositories

If you're writing a library that has dependencies, you should define a constant that
Expand Down
8 changes: 5 additions & 3 deletions coursier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ def _relativize_and_symlink_file(repository_ctx, absolute_path):
# location of `java`.
def _generate_java_jar_command(repository_ctx, jar_path):
java_home = repository_ctx.os.environ.get("JAVA_HOME")
coursier_opts = repository_ctx.os.environ.get("COURSIER_OPTS", "")
coursier_opts = coursier_opts.split(" ") if len(coursier_opts) > 0 else []

if java_home != 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.
java = repository_ctx.path(java_home + "/bin/java")
cmd = [java, "-noverify", "-jar"] + _get_java_proxy_args(repository_ctx) + [jar_path]
cmd = [java, "-noverify", "-jar"] + coursier_opts + _get_java_proxy_args(repository_ctx) + [jar_path]
elif repository_ctx.which("java") != None:
# Use 'java' from $PATH
cmd = [repository_ctx.which("java"), "-noverify", "-jar"] + _get_java_proxy_args(repository_ctx) + [jar_path]
cmd = [repository_ctx.which("java"), "-noverify", "-jar"] + coursier_opts + _get_java_proxy_args(repository_ctx) + [jar_path]
else:
# Try to execute coursier directly
cmd = [jar_path] + ["-J%s" % arg for arg in _get_java_proxy_args(repository_ctx)]
cmd = [jar_path] + coursier_opts + ["-J%s" % arg for arg in _get_java_proxy_args(repository_ctx)]

return cmd

Expand Down

0 comments on commit 2a2c079

Please sign in to comment.