-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Setting version of java_export() jar via command line flag #618
Comments
I have a similar use case, where we use the commit sha as the version. I raised the same question on Bazel Slack, and I have a working solution with @shs96c's help. Just posting it as a reference for future readers. I ended up creating a repository rule and expose some constants. Mostly influenced by https://stackoverflow.com/a/65401963/3528626. def _maven_configuration_impl(repository_ctx):
_BUILD_FILE = """
# DO NOT EDIT: automatically generated for _maven_configuration rule
filegroup(
name = 'files',
srcs = glob(['**']),
visibility = ['//visibility:public']
)
"""
repository_ctx.file("BUILD", _BUILD_FILE, False)
branch = repository_ctx.os.environ.get("CI_COMMIT_BRANCH")
repo = "..."
version = repository_ctx.os.environ.get("CI_COMMIT_SHORT_SHA", "LOCAL")
if branch != "main":
version = version + "-SNAPSHOT"
_MAVEN_CONSTANTS_FILE = """
# DO NOT EDIT: automatically generated for _maven_configuration rule
MAVEN_REPO = \"{repo}\"
MAVEN_VERSION = \"{version}\"
"""
repository_ctx.file(
"constants.bzl",
_MAVEN_CONSTANTS_FILE.format(repo = repo, version = version),
False
)
_maven_configuration = repository_rule(
implementation = _maven_configuration_impl,
environ = [
"CI_COMMIT_BRANCH",
"CI_COMMIT_SHORT_SHA",
],
)
def maven_configuration():
_maven_configuration(name = "maven_configuration") Loaded the rule in WORKSPACE. load("//rules/java:maven_configuration.bzl", "maven_configuration")
maven_configuration() And used the VERSION constant in the BUILD file of the library: load("@maven_configuration//:constants.bzl", "MAVEN_VERSION")
…
maven_coordinates = "com.datadog.lib:lib:%s" % MAVEN_VERSION, |
Is there a way to set the version number of the published jar on the command line? If I use an environment variable in the maven_coordinates, it almost works, but it's not substituted in the pom template. I can create my own pom template and do the string replacement via
--define=
but then I need to set the version in two places. Once by exporting the variable for its use inmaven_coordinates
and again in a--define=maven_version=0.0.0
. Is there a better way to set the version once on the command line and get it applied to themaven_coordinates
and the pom file? I've seen a lot of projects using a jenkins build number as part of the published jar version.The text was updated successfully, but these errors were encountered: