Bazel
Talks about:
<a class="post-tag post-tag-bazel" href="/tags/bazel">Bazel</a>
bazel users can use the yosql-tooling-cli in their builds by following these steps:
- Download the
yosql-tooling-cli
zip file from the latest release (or any prior version). - Use a java_import rule to capture all
.jar
files used byyosql-tooling-cli
java_import(
name = "yosql_tooling_cli",
jars = [
"lib/yosql-tooling-cli-x.y.z.jar",
"lib/yosql-codegen-x.y.z.jar",
"lib/yosql-models-immutables-x.y.z.jar",
... every other jar file from the 'lib' folder
],
)
- Use a java_binary rule to create a runnable binary for bazel
java_binary(
name = "yosql",
deps = [
":yosql_tooling_cli",
],
main_class = "wtf.metio.yosql.tooling.cli.YoSQL",
)
- Write .sql files in a directory of your choice (e.g.
persistence
)
project/
├── WORKSPACE
├── BUILD
└── persistence/
└── user/
├── findUser.sql
└── addUser.sql
└── item/
├── queryAllItems.sql
└── createItemTable.sql
- Declare a filegroup that contains all of your SQL files:
filegroup(
name = "your-sql-files",
srcs = glob(["persistence/**/*.sql"]),
)
- Generate Java code by calling the previously defined
java_binary
:
genrule(
name = "your-repositories",
srcs = [":your-sql-files"],
outs = [
"com/example/persistence/UserRepository.java",
"com/example/persistence/ItemRepository.java",
... all of your generated code
],
cmd = """
$(location :yosql) generate
""",
tools = [":yosql"],
)
- Depend on the generated sources by using the target name of the generated code in the
srcs
of another rule.