bazel-contrib / bazel-contrib/rules_jvm_external
Accessing transitive dependencies in a genrule for building a Quarkus app via maven
- Dominant language
- Java
- Stars
- 373
- Forks
- 301
- Avg merge
- 7d 17h
- Merged PRs (30d)
- 3
Description
Quarkus integration with Bazel is limited, so I'm trying to build a Quarkus-based app via the following Bazel constructs:
* maven_install - Specify all deps
* pom_file - Auto-populate the dependencies section in my POM file template
* genrule - Call Maven
The Maven build command uses `-Dmaven.repo.local=$(BINDIR)/external/maven/v1/https/repo.maven.apache.org/maven2` to declare the location of the local repository.
My problem is that the local repository directory is not populated with the transitive dependencies, and I need to trial-and-error add the missing entries. It appears as though the local repository is populated via the `cp $< $@` targets in `... external/maven/BUILD`.
Can anything be done to run the "copy" genrules in `... external/maven/BUILD` for all dependencies, including the transitive dependencies, so the local maven repository directory is initialized for a maven build command?
The BUILD looks like this:
```
DEPS = [
"@maven//:org_apache_maven_plugins_maven_compiler_plugin",
"@maven//:org_apache_maven_plugins_maven_jar_plugin",
"@maven//:org_apache_maven_plugins_maven_resources_plugin",
"@maven//:org_apache_maven_plugins_maven_surefire_plugin",
"@maven//:io_quarkus_quarkus_maven_plugin",
]
# Override as many Maven settings as possible to create a hermetic environment
genrule(
name = "pkg",
srcs = [
":pom",
"reflection-config.json",
] + DEPS + glob(["src/main/**"]),
outs = ["pkg.tar"],
cmd = (
"TARGET_TMP_DIR=$$(mktemp -d) && " +
"echo '' > $${TARGET_TMP_DIR}/settings && " +
"echo '' > $${TARGET_TMP_DIR}/toolchains && " +
"/usr/bin/mvn " +
"-X " +
"--global-settings $${TARGET_TMP_DIR}/settings " +
"--global-toolchains $${TARGET_TMP_DIR}/toolchains " +
"--settings $${TARGET_TMP_DIR}/settings " +
"--toolchains $${TARGET_TMP_DIR}/toolchains " +
"--offline " +
"--fail-fast " +
"-f $(execpath :pom) " +
"-Dmaven.home=$${PWD}/myapp " +
"-Dmaven.multiModuleProjectDirectory=$$PWD " +
"-Dmaven.repo.local=$(BINDIR)/external/maven/v1/https/repo.maven.apache.org/maven2 " +
"package"
),
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
)
pom_file(
name = "pom",
targets = [":dummy"],
template_file = "pom-template.xml",
substitutions = {
"compiler_plugin_version": "3.8.1",
"dependency_plugin_version": "3.1.1",
"maven_resources_plugin_version": "3.1.0",
"maven_jar_plugin_version": "3.2.0",
"quarkus_plugin_version": "1.0.1.Final",
"quarkus_platform_version": "1.0.1.Final",
"surefire_plugin_version": "2.22.2",
},
)
java_library(
name = "dummy",
srcs = [
"Dummy.java",
],
deps = DEPS,
)
```
Contributor guide
Research direction
Start by reading the generated external/maven/BUILD file and the maven_install dependency graph, then reproduce the genrule with the listed DEPS and its offline Maven command. Done means the local repository is initialized with the transitive dependencies needed by the Quarkus build without trial-and-error additions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100