Bazel see history edit this page

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:

  1. Download the yosql-tooling-cli zip file from the latest release (or any prior version).
  2. Use a java_import rule to capture all .jar files used by yosql-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
    ],
)
  1. 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",
)
  1. 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
  1. Declare a filegroup that contains all of your SQL files:
filegroup(
  name = "your-sql-files",
  srcs = glob(["persistence/**/*.sql"]),
)
  1. 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"],
)
  1. Depend on the generated sources by using the target name of the generated code in the srcs of another rule.