diff --git a/examples/dagger/BUILD b/examples/dagger/BUILD index 1d567601d..15d49c594 100644 --- a/examples/dagger/BUILD +++ b/examples/dagger/BUILD @@ -34,11 +34,29 @@ rm TeaPot.kt toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"], ) +genrule( + name = "chai_lib_src", + outs = ["chai_lib_src.srcjar"], + cmd = """ +cat << EOF > ChaiCup.kt +package chai +object ChaiCup { + fun isEmpty() = true +} +EOF +$(JAVABASE)/bin/jar -cf $@ ChaiCup.kt +rm ChaiCup.kt +""", + toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"], +) + + kt_jvm_library( name = "coffee_lib", srcs = glob(["src/**"]) + [ # Adding a file ending with .srcjar is how code generation patterns are implemented. ":tea_lib_src", + ":chai_lib_src", ], deps = [ "//third_party:dagger", diff --git a/examples/dagger/src/coffee/CoffeeApp.kt b/examples/dagger/src/coffee/CoffeeApp.kt index 68bd6732e..a465f358d 100644 --- a/examples/dagger/src/coffee/CoffeeApp.kt +++ b/examples/dagger/src/coffee/CoffeeApp.kt @@ -18,6 +18,7 @@ package coffee import dagger.Component import kotlinx.coroutines.runBlocking import tea.TeaPot +import chai.ChaiCup import javax.inject.Singleton class CoffeeApp { @@ -30,7 +31,7 @@ class CoffeeApp { companion object { @JvmStatic fun main(args: Array) { - if (TeaPot.isEmpty()) { + if (TeaPot.isEmpty() && ChaiCup.isEmpty()) { val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build() runBlocking { coffeeShop.maker().brew() diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt index 3a61e5e08..7039837fb 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt @@ -24,10 +24,15 @@ class SourceJarExtractor(destDir: Path, val fileMatcher: Predicate = Pre val sourcesList = mutableListOf() override fun preWrite(isDirectory: Boolean, target: Path): Boolean { - if (!isDirectory && fileMatcher.test(target.toString())) { + if (isDirectory) { + return true + } + + if (fileMatcher.test(target.toString())) { sourcesList.add(target.toString()) + return true } - return true + return false } fun execute() {