Merge "maven_jar: Add support to consume snapshot dependencies"

This commit is contained in:
David Pursehouse
2019-04-22 06:18:39 +00:00
committed by Gerrit Code Review
2 changed files with 34 additions and 1 deletions

View File

@@ -430,6 +430,19 @@ And corresponding WORKSPACE excerpt:
)
----
== Building against SNAPSHOT Maven JARs
To build against SNAPSHOT Maven JARs, the complete SNAPSHOT version must be used:
[source,python]
----
maven_jar(
name = "pac4j-core",
artifact = "org.pac4j:pac4j-core:3.5.0-SNAPSHOT-20190112.120241-16",
sha1 = "da2b1cb68a8f87bfd40813179abd368de9f3a746",
)
----
[[consume-jgit-from-development-tree]]
To consume the JGit dependency from the development tree, edit

View File

@@ -8,6 +8,10 @@ MAVEN_LOCAL = "MAVEN_LOCAL:"
ECLIPSE = "ECLIPSE:"
MAVEN_SNAPSHOT = "https://oss.sonatype.org/content/repositories/snapshots"
SNAPSHOT = "-SNAPSHOT-"
def _maven_release(ctx, parts):
"""induce jar and url name from maven coordinates."""
if len(parts) not in [3, 4]:
@@ -20,9 +24,25 @@ def _maven_release(ctx, parts):
group, artifact, version = parts
file_version = version
repository = ctx.attr.repository
if "-SNAPSHOT-" in version:
start = version.index(SNAPSHOT)
end = start + len(SNAPSHOT) - 1
# file version without snapshot constant, but with post snapshot suffix
file_version = version[:start] + version[end:]
# version without post snapshot suffix
version = version[:end]
# overwrite the repository with Maven snapshot repository
repository = MAVEN_SNAPSHOT
jar = artifact.lower() + "-" + file_version
url = "/".join([
ctx.attr.repository,
repository,
group.replace(".", "/"),
artifact,
version,