I am working on a gradle plugin that defines a custom task that is of type JavaCompile
so far I have this setup
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.