# Get JavaCompile task to compile kotlin sources

**URL:** https://discuss.gradle.org/t/get-javacompile-task-to-compile-kotlin-sources/35551
**Category:** Help/Discuss
**Created:** [April 4, 2020, 3:14pm UTC](https://discuss.gradle.org/t/get-javacompile-task-to-compile-kotlin-sources/35551 "2020-04-04T15:14:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![shadowface](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shadowface/32/8552_2.png) [@shadowface](https://discuss.gradle.org/u/shadowface)
#### Post date: [April 4, 2020, 3:14pm UTC](https://discuss.gradle.org/t/get-javacompile-task-to-compile-kotlin-sources/35551/1 "2020-04-04T15:14:01Z")

</div>

I am working on a gradle plugin that defines a custom task that is of type `JavaCompile` so far I have this setup

```gradle
private fun Project.runConfiguration(variants: DomainObjectSet<out BaseVariant>) {
        variants.all { variant ->
            val outputDir = buildDir.resolve("generated/source/plugin/${variant.name}/")
            val classPath = variant.getCompileClasspath(null)
            val once = AtomicBoolean()
            addSourceSets(sourcePath = outputDir.path)

            variant.outputs.all {
                if (once.compareAndSet(false, true)) {
                    tasks.create(
                            "myTaskName",
                            JavaCompile::class.java
                    ) { compiler ->
                        with(compiler.options) {
                            isFork = true
                            isIncremental = true
                        }
                        with(compiler) {
                            group = TASK_GROUP
                            destinationDir = outputDir
                            classpath = classPath
                            options.annotationProcessorPath = classPath
                            source = files(projectDir.resolve("src/main/java")).asFileTree
                        }
                    }
                }
            }
        }
    }

```

When I run this task it completes with an error `no sources or classes found`. According to my investigation this is happening because there were no `.java` file within the source path I have pointed the task to.  
My original idea is to make this plugin support `kotlin` and not `java` sources and to only work as an `android-plugin` and not for `kotlin` projects.

When it comes to android it’s tricky to get the task that compiles the `kotlin` source files (`.kt`) into a `.java` files cuz android creates a separate task named `compile${variant.name.Capitalize()}Kotlin` to compile `.kt` files into `.java` files.

I followed my instinct and pointed my task to the source path to the compiled `.java` files but it doesn’t seem to work, same error `no sources or classes found`.

Should I make my task run last at all? How is that possible?

Also maybe I am tackling this issue from a wrong perspective so please feel free to suggest other ways towards achievement.

Thanks in advance.
