Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kt_compiler_plugin not working with android_binary #388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ maven_install(
"junit:junit:4.12",
"androidx.test.espresso:espresso-core:3.1.1",
"org.hamcrest:hamcrest-library:1.3",
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc",
],
repositories = [
"https://jcenter.bintray.com/",
Expand Down
13 changes: 12 additions & 1 deletion examples/android/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_android_library")

kt_compiler_plugin(
name = "serialization_plugin",
deps = [
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
],
)

kt_android_library(
name = "lib",
Expand All @@ -7,6 +14,10 @@ kt_android_library(
manifest = "src/main/AndroidManifest.xml",
visibility = ["//visibility:public"],
deps = [
"@maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
"@maven//:androidx_appcompat_appcompat",
],
plugins = [
":serialization_plugin",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package examples.android.lib

import kotlinx.serialization.Serializable

@Serializable
data class Data(val stringValue: String, val intValue: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ class MainActivity : Activity() {
.setTitle("Blah")
.setMessage("Blah blah blah?")
.show()
// Ensure Serialization plugin has run and generated code correctly.
Data.serializer()
}
}
2 changes: 1 addition & 1 deletion kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar, compile_jar):
dirs = _compiler_directories(ctx)
srcs = _partitioned_srcs(ctx.files.srcs)
friend = _compiler_friends(ctx, friends = getattr(ctx.attr, "friends", []))
compile_deps = _compiler_deps(toolchains, friend, deps = ctx.attr.deps + ctx.attr.plugins)
compile_deps = _compiler_deps(toolchains, friend, deps = ctx.attr.deps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this sneak in? Or is it part of the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the fix. Including plugins as compile deps produces the error in the PR description

annotation_processors = _plugin_mappers.targets_to_annotation_processors(ctx.attr.plugins + ctx.attr.deps)
transitive_runtime_jars = _plugin_mappers.targets_to_transitive_runtime_jars(ctx.attr.plugins + ctx.attr.deps)
plugins = ctx.attr.plugins
Expand Down