diff --git a/docs/kotlin.md b/docs/kotlin.md
index aaa1b9ba7..d95a8b089 100755
--- a/docs/kotlin.md
+++ b/docs/kotlin.md
@@ -51,9 +51,9 @@ kt_js_library(name, name, add_exports, release, warn, x_ep_disable_all_checks, x_explicit_api_mode,
x_lint, xd_suppress_notes)
-
+
Define java compiler options for `kt_jvm_*` rules with java sources.
-
+
**ATTRIBUTES**
@@ -78,14 +78,14 @@ kt_jvm_binary(name, module_name, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps,
srcs)
-
+
Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper
shell script uses a classpath that includes, among other things, a jar file for each library on which the binary
depends.
-
+
**Note:** This rule does not have all of the features found in [`java_binary`](https://docs.bazel.build/versions/master/be/java.html#java_binary).
It is appropriate for building workspace utilities. `java_binary` should be preferred for release artefacts.
-
+
**ATTRIBUTES**
@@ -116,11 +116,11 @@ kt_jvm_binary(name, name, deps, exported_compiler_plugins, exports, jar, jars, neverlink, runtime_deps,
srcjar)
-
+
Import Kotlin jars.
-
+
## examples
-
+
```bzl
# Old style usage -- reference file groups, do not used this.
kt_jvm_import(
@@ -130,7 +130,7 @@ kt_jvm_import(name, name, name, name, kotlinc_opts, module_name, neverlink, plugins, resource_jars, resource_strip_prefix,
resources, runtime_deps, srcs)
-
+
This rule compiles and links Kotlin and Java sources into a .jar file.
-
+
**ATTRIBUTES**
@@ -204,13 +204,13 @@ kt_jvm_library(name, name, associates, data, deps, env, javac_opts, jvm_flags, kotlinc_opts, main_class,
+kt_jvm_test(name, associates, data, deps, env, env_inheritjavac_opts, jvm_flags, kotlinc_opts, main_class,
module_name, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs,
test_class)
-
+
Setup a simple kotlin_test.
-
+
**Notes:**
* The kotlin test library is not added implicitly, it is available with the label
`@rules_kotlin//kotlin/compiler:kotlin-test`.
@@ -226,6 +226,7 @@ kt_jvm_test(name, data | The list of files needed by this rule at runtime. See general comments about data
at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] |
|deps | A list of dependencies of this rule.See general comments about deps
at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] |
|env | Specifies additional environment variables to set when the target is executed by bazel test. | Dictionary: String -> String | optional | {} |
+|env_inherit | List of environment variable names to be inherited fro the external environment. | List of strings | optional | [] |
|javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
|jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution. | List of strings | optional | [] |
|kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
@@ -250,12 +251,12 @@ kt_jvm_test(name, name, android_rules_enabled, editorconfig, experimental_rules_enabled)
-
+
Used to configure ktlint.
-
+
`ktlint` can be configured to use a `.editorconfig`, as documented at
https://github.com/pinterest/ktlint/#editorconfig
-
+
**ATTRIBUTES**
@@ -274,9 +275,9 @@ ktlint_config(name, name, config, srcs)
-
+
Lint Kotlin files and automatically fix them as needed
-
+
**ATTRIBUTES**
@@ -294,9 +295,9 @@ ktlint_fix(name, con
ktlint_test(name, config, srcs)
-
+
Lint Kotlin files, and fail if the linter raises errors.
-
+
**ATTRIBUTES**
@@ -318,12 +319,12 @@ ktlint_test(name,
kt_compiler_plugin(name, compile_phase, deps, id, options, stubs_phase, target_embedded_compiler)
-
+
Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the `plugins` attribute
of the `kt_jvm_*` rules.
-
+
An example can be found under `//examples/plugin`:
-
+
```bzl
kt_compiler_plugin(
name = "open_for_testing_plugin",
@@ -335,12 +336,12 @@ kt_compiler_plugin(name, name, name, name, add_exports, release, warn, x_ep_disable_all_checks, x_explicit_api_mode,
x_lint, xd_suppress_notes)
-
+
Define java compiler options for `kt_jvm_*` rules with java sources.
-
+
**ATTRIBUTES**
@@ -404,9 +405,9 @@ kt_kotlinc_options(name, x_no_receiver_assertions, x_no_source_debug_extension, x_optin, x_report_perf,
x_sam_conversions, x_skip_prerelease_check, x_use_fir_lt, x_use_k2)
-
+
Define kotlin compiler options.
-
+
**ATTRIBUTES**
diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl
index 4c6569829..7404a779b 100644
--- a/kotlin/internal/jvm/impl.bzl
+++ b/kotlin/internal/jvm/impl.bzl
@@ -306,7 +306,7 @@ def kt_jvm_junit_test_impl(ctx):
direct = ctx.files._java_runtime,
),
# adds common test variables, including TEST_WORKSPACE.
- testing.TestEnvironment(environment = ctx.attr.env),
+ testing.TestEnvironment(environment = ctx.attr.env, inherited_environment = ctx.attr.env_inherit),
)
_KtCompilerPluginClasspathInfo = provider(
diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl
index bef495e43..386cb2aa3 100644
--- a/kotlin/internal/jvm/jvm.bzl
+++ b/kotlin/internal/jvm/jvm.bzl
@@ -353,6 +353,9 @@ Setup a simple kotlin_test.
doc = "Specifies additional environment variables to set when the target is executed by bazel test.",
default = {},
),
+ "env_inherit": attr.string_list(
+ doc = "Environment variables to inherit from the external environment.",
+ ),
"_lcov_merger": attr.label(
default = Label("@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main"),
),