The following section discusses on how to build and run tests for Knora-API with Bazel.
To install the Bazel build tool, follow these steps:
$ npm install -g @bazel/bazelisk
This will install bazelisk which is
a wrapper to the bazel
binary. It will, when the bazel
command ir run,
automatically install the supported Bazel version, defined in the .bazelversion
file in the root of the knora-api
repository.
Build webapi
:
# build webapi
$ bazel build //webapi/...
# run all webapi tests
$ bazel test //webapi//...
The Bazel build is defined in a number of files:
- WORKSPACE - here are external dependencies defined
- BUILD - there are a number of BUILD files throughout the directory structure where each represents a separate package responsible for everything underneath.
- *.bzl - custom extensions loaded and used in BUILD files
For a more detailed discussion, please see the Concepts and Terminology section in the Bazel documentation.
-
Override some
.bazelrc
settings in your own copy created at~/.bazelrc
:build --action_env=PATH="/usr/local/bin:/opt/local/bin:/usr/bin:/bin" build --strategy=Scalac=worker build --worker_sandboxing query --package_path %workspace%:/usr/local/bin/bazel/base_workspace startup --host_jvm_args=-Djavax.net.ssl.trustStore=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/lib/security/cacerts \ --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit
-
Add Bazel Plugin and Project to IntelliJ
- The latest version of the Bazel plugin
supports only IntelliJ upto version
2019.03.05
. After you make sure to run this version of IntelliJ, install the plugin from inside IntelliJ. - Click on
File -> Import Bazel Project
and select twicenext
. - Uncomment the
Scala
language and clickFinish
.
- The latest version of the Bazel plugin
supports only IntelliJ upto version
-
Run single spec:
$ bazel test //webapi/src/test/scala/org/knora/webapi/e2e/v1:SearchV1R2RSpec
-
Run single spec and only tests containing
gaga
in the description$ bazel test //webapi/src/test/scala/org/knora/webapi/e2e/v1:SearchV1R2RSpec --test_arg=-z --test_arg="gaga"
-
Optimized development workflow
The first time:
make docker-build
# run at least once so that you have all Docker imagesmake init-db-test
# stops webapi, deletes and runs only the DB container, creates the repository and loads the datamake stack-up-fast
# starts the whole stack and only rebuilds theknora-api
Docker container if necessary
After you made some changes to webapi:
make init-db-test
# stops, webapi, deletes and runs only the DB container, creates the repository and loads the datamake stack-up-fast
# starts the whole stack and only rebuilds theknora-api
Docker container if necessary
-
Start Scala REPL
$ bazel run //webapi:main_library_repl
-
xxx
$
$
$