2

running bazel build //... \ --aspects some-aspect.bzl%some_aspect \ --output_groups=some_new_output,default does not create test jars outputs.

on the other hand running bazel test does create the test jar outputs:

bazel test //... \ --aspects some-aspect.bzl%some_aspect \ --output_groups=some_new_output,default

How come?

This question was updated to reflect use of aspects: The original question:

running bazel build //... does not add test code to output jar.

on the other hand bazel test //... builds the test code but also runs it.

Is there a way in bazel to build the test code without running the tests?

Natan
  • 1,944
  • 1
  • 11
  • 16

2 Answers2

2

I had a mistake in the values I gave the --output_groups flag.

It should have been --output_groups=+some_new_output,+default

The default can even be omitted:

--output_groups=+some_new_output

This flag is not documented at all. There is an open issue on this in bazel github repo.

Natan
  • 1,944
  • 1
  • 11
  • 16
0

You may be looking for --build_tests_only.

László
  • 3,973
  • 1
  • 13
  • 26
  • `--build_tests_only` seems not to be the answer I'm looking for, because with it the tests are still being run. any other way to build the test code fully without running the tests? – Natan Jun 20 '17 at 15:59
  • Can you clarify what you mean by "running bazel build //... does not add test code to output jar." ? What does "bazel test" build that "bazel build" doesn't? – László Jun 21 '17 at 07:11
  • Sure. from my experiments, I've noticed that ```bazel build //...``` does not build test jars (specifically jars originating from `scala_specs2_junit_test`), But ```bazel test //...``` does build them – Natan Jun 22 '17 at 15:32
  • @Natan: Yes, but my repro attempt was unsuccesful: I cloned [@bazelbuild/rules_scala](https://github.com/bazelbuild/rules_scala), and with bazel-0.5.2 on Linux, I ran `bazel clean`, `bazel build //test:data_location_expansion`, `bazel test //test:data_location_expansion`. I also ran `find bazel-bin/test -name '*.jar' -not -path '*.runfiles/*'` after the latter two, and in both cases the result was just `bazel-bin/test/data_location_expansion.jar`. Do you see the same? How can I repro what you see? – László Jul 04 '17 at 15:23
  • I'v realized that I left out that I run the commands with aspects flags... I apologize for not giving out complete details about the problem. I found out what was the problem. I will update the question and provide an answer. – Natan Jul 05 '17 at 11:06