@@ -21,135 +21,105 @@ specs2_junit_repositories()
2121specs2_junit_toolchain()
2222```
2323
24- ### Configuring JUnit dependencies via toolchain
24+ ### Configuring testing dependencies via toolchain
25+
26+ Default dependencies, which come preconfigured with Rules Scala repositories are mostly tailored
27+ towards supporting Rules Scala codebase, and may miss specific versions or libraries for your
28+ usecase. You should prefer configuring dependencies via toolchains.
29+
30+ Test framework dependencies are configured via testing toolchain. For convenience, macro
31+ ` setup_scala_testing_toolchain ` can be used to define such toolchains.
2532
26- ` BUILD ` file content in your preferred package:
2733``` starlark
28- load(" @io_bazel_rules_scala//scala:providers .bzl" , " declare_deps_provider " )
29- load( " @io_bazel_rules_scala//testing/toolchain:toolchain.bzl " , " scala_testing_toolchain " )
34+ load(" @io_bazel_rules_scala//scala:scala .bzl" , " setup_scala_testing_toolchain " )
35+ ```
3036
31- scala_testing_toolchain(
32- name = " testing_toolchains_with_junit" ,
33- dep_providers = [
34- " :junit_classpath_provider" ,
35- ],
36- visibility = [" //visibility:public" ],
37- )
37+ Attributes
3838
39- toolchain(
40- name = " testing_toolchain" ,
41- toolchain = " :testing_toolchains_with_junit" ,
42- toolchain_type = " @io_bazel_rules_scala//testing/toolchain:testing_toolchain_type" ,
43- visibility = [" //visibility:public" ],
44- )
39+ - ` name ` - toolchain name
40+ - ` visibility ` - optional, default value is ` ["//visibility:public"] `
41+ - ` scalatest_classpath ` - List of ScalaTest deps, can be omitted if ScalaTest rules won't be used.
42+ - ` junit_classpath ` - List of Junit 4 deps, required for Specs2 and JUnit rules support. Otherwise,
43+ can
44+ be omitted.
45+ - ` specs2_classpath ` - List of Specs2 deps, requires ` specs2_junit_classpath ` and ` junit_classpath `
46+ to be provided alongside.
47+ - ` specs2_junit_classpath ` - Specs2 JUnit runner dep, required for Specs2 rules as the use JUnit
48+ runner.
49+
50+ Examples (assumes maven deps are managed with rules_jvm_external):
4551
46- declare_deps_provider(
47- name = " junit_classpath_provider" ,
48- deps_id = " junit_classpath" ,
49- visibility = [" //visibility:public" ],
50- deps = [
51- " @my_hamcrest_core" ,
52- " @my_junit" ,
52+ #### ScalaTest (flat spec with must matchers)
53+
54+ ``` starlark
55+ # BUILD
56+ load(" @io_bazel_rules_scala//scala:scala.bzl" , " setup_scala_testing_toolchain" )
57+
58+ setup_scala_testing_toolchain(
59+ name = " scalatest_toolchain" ,
60+ scalatest_classpath = [
61+ " @maven//:org_scalactic_scalactic_2_13" ,
62+ " @maven//:org_scalatest_scalatest_2_13" ,
63+ " @maven//:org_scalatest_scalatest_compatible" ,
64+ " @maven//:org_scalatest_scalatest_core_2_13" ,
65+ " @maven//:org_scalatest_scalatest_flatspec_2_13" ,
66+ " @maven//:org_scalatest_scalatest_matchers_core_2_13" ,
67+ " @maven//:org_scalatest_scalatest_mustmatchers_2_13" ,
5368 ],
5469)
5570```
56- Register toolchain
71+ Register the toolchain
5772``` starlark
5873# WORKSPACE
59- register_toolchains(' //my/package:testing_toolchains_with_junit ' )
74+ register_toolchains(' //:scalatest_toolchain ' )
6075```
61- ` junit_classpath_provider ` (deps_id ` junit_classpath ` ) is where classpath required for junit tests
62- is defined.
63-
64- ### ScalaTest dependencies can be configured by declaring a provider with an id ` scalatest_classpath ` :
6576
77+ #### JUnit 4
6678``` starlark
67- # my/package/BUILD
68- scala_testing_toolchain(
69- name = " testing_toolchains_with_scalatest" ,
70- dep_providers = [
71- " :scalatest_classpath_provider" ,
72- ],
73- visibility = [" //visibility:public" ],
74- )
75-
76- toolchain(
77- name = " testing_toolchain" ,
78- toolchain = " :testing_toolchains_with_scalatest" ,
79- toolchain_type = " @io_bazel_rules_scala//testing/toolchain:testing_toolchain_type" ,
80- visibility = [" //visibility:public" ],
81- )
82-
83- declare_deps_provider(
84- name = " scalatest_classpath_provider" ,
85- deps_id = " junit_classpath" ,
86- visibility = [" //visibility:public" ],
87- deps = [
88- " @scalactic" ,
89- " @scalatest" ,
79+ # BUILD
80+ load(" @io_bazel_rules_scala//scala:scala.bzl" , " setup_scala_testing_toolchain" )
81+
82+ setup_scala_testing_toolchain(
83+ name = " junit_toolchain" ,
84+ junit_classpath = [
85+ " @maven//:junit_junit" ,
86+ " @maven//:org_hamcrest_hamcrest_core" ,
9087 ],
9188)
9289```
93- Register toolchain
90+ Register the toolchain
9491``` starlark
9592# WORKSPACE
96- register_toolchains(' //my/package:testing_toolchains_with_scalatest ' )
93+ register_toolchains(' //:junit_toolchain ' )
9794```
9895
99- ### Specs2 with Junit support can be configured by declaring providers with
100- ` junit_classpath_provider ` , ` specs2_classpath_provider ` , ` specs2_junit_classpath_provider ` ids:
96+ #### Specs2
97+ For Specs2 rules to work, ` junit_classpath ` , ` specs2_junit_classpath ` and ` specs2_classpath ` must
98+ be configured.
10199``` starlark
102- # my/package/BUILD
103- scala_testing_toolchain(
104- name = " testing_toolchains_with_specs2_junit_impl" ,
105- dep_providers = [
106- " :junit_classpath_provider" ,
107- " :specs2_classpath_provider" ,
108- " :specs2_junit_classpath_provider" ,
100+ # BUILD
101+ load(" @io_bazel_rules_scala//scala:scala.bzl" , " setup_scala_testing_toolchain" )
102+
103+ setup_scala_testing_toolchain(
104+ name = " specs2_toolchain" ,
105+ junit_classpath = [
106+ " @maven//:junit_junit" ,
107+ " @maven//:org_hamcrest_hamcrest_core" ,
109108 ],
110- visibility = [" //visibility:public" ],
111- )
112-
113- toolchain(
114- name = " testing_toolchains_with_specs2_junit" ,
115- toolchain = " :testing_toolchains_with_specs2_junit_impl" ,
116- toolchain_type = " @io_bazel_rules_scala//testing/toolchain:testing_toolchain_type" ,
117- visibility = [" //visibility:public" ],
118- )
119-
120- declare_deps_provider(
121- name = " junit_classpath_provider" ,
122- deps_id = " junit_classpath" ,
123- visibility = [" //visibility:public" ],
124- deps = [
125- " @my_hamcrest_core" ,
126- " @my_junit" ,
109+ specs2_junit_classpath = [
110+ " @maven//:org_specs2_specs2_junit_2_12" ,
127111 ],
128- )
129-
130- declare_deps_provider(
131- name = " specs2_classpath_provider" ,
132- deps_id = " specs2_classpath" ,
133- visibility = [" //visibility:public" ],
134- deps = [
135- " @my_specs2_common" ,
136- " @my_specs2_core" ,
137- " @my_specs2_fp" ,
138- " @my_specs2_matcher" ,
139- ],
140- )
141-
142- declare_deps_provider(
143- name = " specs2_junit_classpath_provider" ,
144- deps_id = " specs2_junit_classpath" ,
145- visibility = [" //visibility:public" ],
146- deps = [
147- " @my_specs2_junit" ,
148- ],
149- )
112+ specs2_classpath = [
113+ " @maven//:org_specs2_specs2_common_2_12" ,
114+ " @maven//:org_specs2_specs2_core_2_12" ,
115+ " @maven//:org_specs2_specs2_fp_2_12" ,
116+ " @maven//:org_specs2_specs2_junit_2_12" ,
117+ " @maven//:org_specs2_specs2_matcher_2_12" ,
118+ ]
119+ )
150120```
151- Register toolchain
121+ Register the toolchain
152122``` starlark
153123# WORKSPACE
154- register_toolchains(' //my/package:testing_toolchains_with_specs2_junit ' )
124+ register_toolchains(' //:specs2_toolchain ' )
155125```
0 commit comments