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

Add support for custom java install with coursier #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cristi-
Copy link

@cristi- cristi- commented Mar 11, 2021

We are using this to avoid java versions mismatch between environments (where some machines may have jdk1.8 or jdk14 instead of jdk11), which causes pinning to generate different results.

A rough example of how we use this with a repository_rule

JAVA_EXEC_TEMPLATE = """
#!/usr/bin/env bash
exec %s "$@"
"""

BUILD_FILE_CONTENTS = """
exports_files(["java"])
"""

def _jdkenv(repository_ctx):
    cwd = repository_ctx.execute(["pwd"]).stdout.strip()
    java_bin = check_path_or_download_jdk11()
    repository_ctx.file(
        "java",
        content = JAVA_EXEC_TEMPLATE % java_bin,
        executable = True,
    )

    repository_ctx.file("BUILD", content = BUILD_FILE_CONTENTS)
jdkenv = repository_rule(
    implementation = _jdkenv,
    environ = ["JAVA_HOME"],
    doc = """Repository rule for detecting jdk11:
@repo//:java -- Java binary
""",

And in maven_install:

load("@rules_jvm_external//:defs.bzl", "maven_install")
load("//tools/build:jdk.bzl", "jdkenv")

jdkenv(
    name = "jdk11",
)
maven_install(
        name = "jdk_deps",
        ....
        java_binary = "@jdk11//:java",
)   

@cristi- cristi- changed the title Add support for custom java install for coursier Add support for custom java install with coursier Mar 11, 2021
@cristi- cristi- marked this pull request as ready for review March 11, 2021 10:28
@shs96c
Copy link
Collaborator

shs96c commented Mar 11, 2021

Is there any reason not to use the JAVA_BASE environment variable? That should mean your build and coursier would share the same JDK.... https://docs.bazel.build/versions/master/be/make-variables.html#custom_variables

@cristi-
Copy link
Author

cristi- commented Mar 11, 2021

Is there any reason not to use the JAVA_BASE environment variable? That should mean your build and coursier would share the same JDK.... https://docs.bazel.build/versions/master/be/make-variables.html#custom_variables

I was looking at #445 (comment) and I thought it would be impossible to access the path as provided by JAVA_BASE. Do you think there is a way to get to provide the path to coursier ?

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

Successfully merging this pull request may close these issues.

None yet

3 participants