Skip to content

Instantly share code, notes, and snippets.

@jmmk

jmmk/App.kt Secret

Last active November 16, 2017 02:58
Show Gist options
  • Save jmmk/842fac837b7af8ebefde85e476f9002d to your computer and use it in GitHub Desktop.
Save jmmk/842fac837b7af8ebefde85e476f9002d to your computer and use it in GitHub Desktop.
Kotlin Bazel
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
fun main(args: Array<String>) {
val mapper = jacksonObjectMapper()
println("Hello World")
}
load("@org_pubref_rules_kotlin//kotlin:rules.bzl", "kotlin_binary")
kotlin_binary(
name = "main",
main_class = "AppKt",
srcs = ["App.kt"],
java_deps = [
"@jackson//:compile",
],
compile_args = [
"-jvm-target", "1.8",
],
)
git_repository(
name = "org_pubref_rules_kotlin",
remote = "https://github.com/pubref/rules_kotlin.git",
commit = "0747953639bcaac923644b16ca7873a41049c340",
)
load('@org_pubref_rules_kotlin//kotlin:rules.bzl', 'kotlin_repositories')
kotlin_repositories()
git_repository(
name = 'org_pubref_rules_maven',
remote = 'https://github.com/pubref/rules_maven',
commit = '9c3b07a6d9b195a1192aea3cd78afd1f66c80710',
)
load('@org_pubref_rules_maven//maven:rules.bzl', 'maven_repositories')
maven_repositories()
load('@org_pubref_rules_maven//maven:rules.bzl', 'maven_repository')
maven_repository(
name = 'jackson',
deps = [
"com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2",
],
transitive_deps = [
'07c10d545325e3a6e72e06381afe469fd40eb701:com.fasterxml.jackson.core:jackson-annotations:2.9.0',
'aed20e50152a2f19adc1995c8d8f307c7efa414d:com.fasterxml.jackson.core:jackson-core:2.9.2',
'1d8d8cb7cf26920ba57fb61fa56da88cc123b21f:com.fasterxml.jackson.core:jackson-databind:2.9.2',
'a9cf72ae68a641ade45c400b6cec2d363818f11b:com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2',
'919f0dfe192fb4e063e7dacadee7f8bb9a2672a9:org.jetbrains:annotations:13.0',
'bfc9458443666b1be1d66813f3a90a03afa30730:org.jetbrains.kotlin:kotlin-reflect:1.1.3',
'e51ebc59da5103a2052859e89682c7f9c3456298:org.jetbrains.kotlin:kotlin-stdlib:1.1.3',
],
)
load('@jackson//:rules.bzl', 'jackson_compile')
jackson_compile()
@jmmk
Copy link
Author

jmmk commented Nov 15, 2017

bazel build //:main

INFO: Found 1 target...
ERROR: /Users/jmmk/Desktop/bazel-kotlin/BUILD:3:1: Compiling 1 Kotlin source files to main_kt.jar failed (Exit 1).
/private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/bazel-sandbox/8617504416877719161/execroot/__main__/App.kt:1:30: error: unresolved reference: module
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
                             ^
/private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/bazel-sandbox/8617504416877719161/execroot/__main__/App.kt:4:16: error: unresolved reference: jacksonObjectMapper
  val mapper = jacksonObjectMapper()
               ^
Target //:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 6.296s, Critical Path: 2.52s

@pcj
Copy link

pcj commented Nov 15, 2017

Can you put verbose=2 in the kotlin_binary rule? Wondering if the jar that contains the jacksonObjectMapper is there.

@jmmk
Copy link
Author

jmmk commented Nov 15, 2017

bazel build //:main

DEBUG: /private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/external/org_pubref_rules_kotlin/kotlin/rules.bzl:76:13: kotlin compile classpath:
external/com_fasterxml_jackson_core_jackson_databind/jar/jackson-databind-2.9.2.jar
external/com_fasterxml_jackson_core_jackson_annotations/jar/jackson-annotations-2.9.0.jar
external/com_fasterxml_jackson_core_jackson_core/jar/jackson-core-2.9.2.jar
external/org_jetbrains_annotations/jar/annotations-13.0.jar.
DEBUG: /private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/external/org_pubref_rules_kotlin/kotlin/rules.bzl:85:9: kotlin compile arguments:
KotlinPreloader
-cp
external/com_github_jetbrains_kotlin/lib/kotlin-compiler.jar
org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
-d
bazel-out/darwin_x86_64-fastbuild/bin/main_kt.jar
-kotlin-home
external/com_github_jetbrains_kotlin/lib/..
-jvm-target
1.8
-cp
external/com_fasterxml_jackson_core_jackson_databind/jar/jackson-databind-2.9.2.jar:external/com_fasterxml_jackson_core_jackson_annotations/jar/jackson-annotations-2.9.0.jar:external/com_fasterxml_jackson_core_jackson_core/jar/jackson-core-2.9.2.jar:external/org_jetbrains_annotations/jar/annotations-13.0.jar
App.kt.
INFO: Found 1 target...
ERROR: /Users/jmmk/Desktop/bazel-kotlin/BUILD:3:1: Compiling 1 Kotlin source files to main_kt.jar failed (Exit 1).
/private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/bazel-sandbox/6320453289190303276/execroot/__main__/App.kt:1:30: error: unresolved reference: module
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
                             ^
/private/var/tmp/_bazel_jmmk/b4a1d5dca7a3dfe59337df9230eb1872/bazel-sandbox/6320453289190303276/execroot/__main__/App.kt:4:16: error: unresolved reference: jacksonObjectMapper
  val mapper = jacksonObjectMapper()
               ^
Target //:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 9.965s, Critical Path: 2.78s

@pcj Looks like it's not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment