Reputation: 31
I'm having issues using maven dependencies when building with bazel. The problem seems to be that the downloaded jar is empty, with only the manifest in it. I've double and triple checked that the path and version are correct and also used the sha1 to ensure that the correct jar is being targeted.
WORKSPACE:
maven_server(
name = "default",
url = "http://central.maven.org/maven2/
)
maven_jar(
name = "org_seleniumhq_selenium_selenium_java",
artifact = "org.seleniumhq.selenium:selenium-java:3.11.0",
sha1 = "05b50d4072e0e51779b6e9f3594106312061bfde"
)
BUILD:
package(default_visibility = ["//visibility:public"])
java_library(
name = "core",
srcs = glob(
["main/core/**/*.java"]
),
resources = glob(["test/resources/*"]),
deps = ["@org_seleniumhq_selenium_selenium_java//jar"]
)
Calling "bazel build //src:core" immediately fails with "error: package org.openqa.selenium does not exist", however I can see that the selenium-java.jar is being created in bazel-e2e-testing/external/org_seleniumhq_selenium_selenium_java, but again, it is empty.
Any suggestions on what I might be doing wrong?
Thanks in advance
Upvotes: 0
Views: 494
Reputation: 31
So, after more investigation on how Bazel works, I've finally figured out the issue and I'll add it here in case anyone stumbles on the same problem in the future.
The main problem is the transitive dependencies, which maven_jar doesn't resolve by default. Instead, there is a useful repository rule provided by bazel called transitive_maven_jar, which can be used to resolve all transitive dependencies. Also, there was an issue with the actual dependency being declared.
In my case, I declared selenium-java as the dependency, however I was only using an import from one of its transitive dependencies (selenium-api). Due to this, selenium-java was not actually being compiled as it wasn't actually used. Once I've declared selenium-api as my dependency, the issue was solved.
Final WORKSPACE:
http_archive(
name = "trans_maven_jar",
url = "https://github.com/bazelbuild/migration-tooling/archive/master.zip",
type = "zip",
strip_prefix = "migration-tooling-master",
)
load("@trans_maven_jar//transitive_maven_jar:transitive_maven_jar.bzl", "transitive_maven_jar")
transitive_maven_jar(
name = "dependencies",
artifacts = [
"org.seleniumhq.selenium:selenium-java:3.11.0",
]
)
load("@dependencies//:generate_workspace.bzl", "generated_maven_jars")
generated_maven_jars()
Final BUILD:
package(default_visibility = ["//visibility:public"])
java_library(
name = "core",
srcs = glob(
["main/core/**/*.java"]
),
resources = glob(["test/resources/*"]),
deps = [
"@org_seleniumhq_selenium_selenium_api//jar"
]
)
Note that I've still not fully understood how bazel works, so part of what I said might not be precisely correct, in which case, please let me know, but this is what worked for me.
Upvotes: 1