Skip to content

Commit

Permalink
Add missing javax.annotation dependency (#320)
Browse files Browse the repository at this point in the history
* Add missing javax.annotation dependency

Fixes #321.

Bazel/Dagger integration requires javax.annotation to be on the
classpath to generate @generated annotation.

Recent ErrorProne releases (started from 2.3.3) added new bug pattern:
RefersToDaggerCodegen that is flagging the code as invalid, as it
doesn't realize that the code is generated.

Due to this problem, a previous attemt to bump EP version in Bazel was
reverted. Fixing it would allow us to make another attempt to update
EP version in Bazel.

Test Plan:

A. Involved approach:

1. Bump EP version to 2.3.4 in Bazel
2. Conduct custom java tools release with new EP version
3. Consume custom java tools release in WORKSPACE in rules_kotlin
4. Trying to bulid rules_kotlin would fail with RefersToDaggerCodegen
   error

B. Simple approach:

1. Apply this patch
2. Build rules_kotlin
3. Confirm that this class:
   KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory
   is annotated with @generated annotation:

@generated(
    value = "dagger.internal.codegen.ComponentProcessor",
    comments = "https://dagger.dev"
)
@SuppressWarnings({
    "unchecked",
    "rawtypes"
})
public final class KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory
[...]

* Add javax.annotation to test_lib rule

* compile.bzl: Remove superfluous paren

* Run buildifier on BUILD files
  • Loading branch information
davido authored May 9, 2020
1 parent 41fc492 commit d59d27b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/plugin/src/serialization/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_test
kt_compiler_plugin(
name = "serialization_plugin",
deps = [
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
],
)

Expand All @@ -24,8 +24,8 @@ kt_jvm_test(
test_class = "plugin.serialization.SerializationTest",
deps = [
":data",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
"@com_github_jetbrains_kotlin//:kotlin-reflect",
"@kotlin_rules_maven//:junit_junit",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
],
)
)
3 changes: 2 additions & 1 deletion kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compi
mnemonic = "KotlinCompile",
inputs = depset(
ctx.files.srcs,
transitive = [compile_deps.compile_jars, transitive_runtime_jars]),
transitive = [compile_deps.compile_jars, transitive_runtime_jars],
),
tools = tools,
input_manifests = input_manifests,
outputs = [f for f in outputs.values()],
Expand Down
1 change: 1 addition & 0 deletions kotlin/internal/repositories/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def kt_configure():
"com.google.dagger:dagger:2.26",
"com.google.dagger:dagger-compiler:2.26",
"com.google.dagger:dagger-producers:2.26",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"org.pantsbuild:jarjar:1.7.2",
],
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ java_library(
"//third_party:dagger",
"@com_github_jetbrains_kotlin//:annotations",
"@com_github_jetbrains_kotlin//:kotlin-stdlib",
"@kotlin_rules_maven//:javax_annotation_javax_annotation_api",
"@kotlin_rules_maven//:javax_inject_javax_inject",
],
)
5 changes: 3 additions & 2 deletions src/test/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ java_library(
"Deps.java",
"DirectoryType.java",
"KotlinAbstractTestBuilder.java",
"KotlinBuilderTestComponent.java",
"KotlinJsTestBuilder.java",
"KotlinJvmTestBuilder.java",
"KotlinBuilderTestComponent.java"
],
data = [
"//src/main/kotlin/io/bazel/kotlin/compiler",
Expand All @@ -52,7 +52,8 @@ java_library(
deps = _COMMON_DEPS + [
"//third_party:autovalue",
"//third_party:dagger",
"//src/main/kotlin/io/bazel/kotlin/builder/tasks"
"@kotlin_rules_maven//:javax_annotation_javax_annotation_api",
"//src/main/kotlin/io/bazel/kotlin/builder/tasks",
],
)

Expand Down

0 comments on commit d59d27b

Please sign in to comment.