在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):pubref/rules_kotlin开源软件地址(OpenSource Url):https://github.com/pubref/rules_kotlin开源编程语言(OpenSource Language):Python 71.8%开源软件介绍(OpenSource Introduction):
Kotlin Rules for BazelBuild Kotlin source with with Bazel.
Workspace rulesAdd the following to your git_repository(
name = "org_pubref_rules_kotlin",
remote = "https://github.com/pubref/rules_kotlin.git",
tag = "v0.5.0", # update as needed
)
load("@org_pubref_rules_kotlin//kotlin:rules.bzl", "kotlin_repositories")
kotlin_repositories() This will fetch a
kotlin release
(currently 1.1.4-3) and load a number of dependencies related to
dagger (used to build the
BUILD rulesAdd the following to your BUILD file: load("@org_pubref_rules_kotlin//kotlin:rules.bzl", "kotlin_library") kotlin_libraryExample: kotlin_library(
name = "my_kotlin_lib",
srcs = ["kotlin_source_file.kt"],
deps = [":some_other_kotlin_library_rule"],
java_deps = [":some_other_java_library_rule", "@another_maven_jar//jar"],
) Use the To compile a set of kotlin sources files with the $ bazel build :my_kotlin_lib
Target :my_kotlin_lib up-to-date:
bazel-bin/.../my_kotlin_lib.jar To use the output of a android_binary(
name = "foo",
deps = [
":my_kotlin_lib_kt`,
]
) kotlin_library attributes
kotlin_binaryA kotlin_binary(
name = "main_kt",
main_class = "my.project.MainKt",
srcs = ["main.kt"],
deps = [":my_kotlin_lib"]
java_deps = [":javalib"]
) To create a self-contained executable jar, invoke the implicit
$ bazel build :main_kt_deploy.jar
Target :main_kt_deploy.jar up-to-date:
bazel-bin/.../main_kt_deploy.jar
$ java -jar ./bazel-bin/.../main_kt_deploy.jar
kotlin_binary attributesIncludes all
kotlin_android_libraryA PACKAGE = "com.company.app"
MANIFEST = "AndroidManifest.xml"
kotlin_android_library(
name = "src",
srcs = glob(["src/**/*.kt"]),
custom_package = PACKAGE,
manifest = MANIFEST,
resource_files = glob(["res/**/*"]),
java_deps = [
"@com_squareup_okhttp3_okhttp//jar",
"@com_squareup_okio_okio//jar",
],
aar_deps = [
"@androidsdk//com.android.support:appcompat-v7-25.3.1",
"@androidsdk//com.android.support:cardview-v7-25.3.1",
"@androidsdk//com.android.support:recyclerview-v7-25.3.1",
],
)
android_binary(
name = "app",
custom_package = PACKAGE,
manifest = MANIFEST,
deps = [
":src",
],
) If you prefer to separate your source files and resource files in
different Bazel rules (for example the resource files are also used
by java PACKAGE = "com.company.app"
MANIFEST = "AndroidManifest.xml"
android_library(
name = "res",
custom_package = PACKAGE,
manifest = MANIFEST,
resource_files = glob(["res/**/*"]),
aar_deps = [
"@androidsdk//com.android.support:appcompat-v7-25.3.1",
"@androidsdk//com.android.support:cardview-v7-25.3.1",
"@androidsdk//com.android.support:recyclerview-v7-25.3.1",
],
)
android_library(
name = "java",
srcs = glob(["src/**/*.java"]),
deps = [
":res",
# And other depedencies
]
)
kotlin_android_library(
name = "kt",
srcs = glob(["src/**/*.kt"]),
aar_deps = [
"@androidsdk//com.android.support:appcompat-v7-25.3.1",
"@androidsdk//com.android.support:cardview-v7-25.3.1",
"@androidsdk//com.android.support:recyclerview-v7-25.3.1",
],
android_deps = [
":res",
]
)
android_binary(
name = "app",
custom_package = PACKAGE,
manifest = MANIFEST,
deps = [
":java",
":kt",
":res",
],
) Please note that if you want to use kotlin_android_library attributesIncludes all
And also kotlin_testThe kotlin_test(
name = "main_kt_test",
test_class = "examples.helloworld.MainKtTest",
srcs = ["MainKtTest.kt"],
size = "small",
deps = [
":rules",
],
java_deps = [
"@junit4//jar",
],
) $ bazel test :main_kt_test.jar
kotlin_compile
The SummaryThat's it! Hopefully these rules with make it easy to mix kotlin and traditional java code in your projects and take advantage of bazel's approach to fast, repeatable, and reliable builds.
ExamplesTo run the examples in this repository, clone the repo: $ git clone https://github.com/pubref/rules_kotlin
$ cd rules_kotlin
$ bazel query //... --output label_kind
$ bazel run examples/helloworld:main_kt
$ bazel run examples/helloworld:main_java
$ bazel test examples/helloworld:main_test
$ bazel test examples/helloworld:main_kt_test TODO
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论