Skip to content

Commit

Permalink
Fix java_plugins to work with Android rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jongerrish committed Nov 23, 2020
1 parent 493a551 commit 02a57b6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ maven_install(
"com.google.dagger:dagger:2.28",
"com.google.dagger:dagger-compiler:2.28",
"com.google.dagger:dagger-producers:2.28",
"com.google.auto.value:auto-value:1.6.5",
"com.google.auto.value:auto-value-annotations:1.6.5",
],
repositories = [
"https://jcenter.bintray.com/",
Expand Down
11 changes: 11 additions & 0 deletions examples/android/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_compiler_plugin")
load("@rules_java//java:defs.bzl", "java_plugin")

kt_compiler_plugin(
name = "serialization_plugin",
Expand All @@ -10,17 +11,27 @@ kt_compiler_plugin(
],
)

java_plugin(
name = "autovalue",
generates_api = 1,
processor_class = "com.google.auto.value.processor.AutoValueProcessor",
deps = ["@maven//:com_google_auto_value_auto_value"],
)

kt_android_library(
name = "lib",
srcs = glob(["src/main/kotlin/**/*.kt"]),
custom_package = "examples.android.lib",
manifest = "src/main/AndroidManifest.xml",
plugins = [
":serialization_plugin",
":autovalue",
],
tags = ["trace"],
visibility = ["//visibility:public"],
deps = [
"@maven//:androidx_appcompat_appcompat",
"@maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
"@maven//:com_google_auto_value_auto_value_annotations"
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ class MainActivity : Activity() {
.show()
// Ensure Serialization plugin has run and generated code correctly.
Data.serializer()

AutoValue_TestKtValue.Builder().setName("Auto Value Test").build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package examples.android.lib

import com.google.auto.value.AutoValue

@AutoValue
abstract class TestKtValue {
abstract fun name(): String
fun builder(): Builder = AutoValue_TestKtValue.Builder()

@AutoValue.Builder
abstract class Builder {
abstract fun setName(name: String): Builder
abstract fun build(): TestKtValue
}
}
2 changes: 1 addition & 1 deletion kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
compile_deps = _jvm_deps(
toolchains,
friend,
deps = ctx.attr.deps + ctx.attr.plugins,
deps = ctx.attr.deps,
runtime_deps = ctx.attr.runtime_deps,
)
annotation_processors = _plugin_mappers.targets_to_annotation_processors(ctx.attr.plugins + ctx.attr.deps)
Expand Down

0 comments on commit 02a57b6

Please sign in to comment.