Open Jolanrensen opened 2 years ago
could you try construction, may be it can help
clean {
delete 'preprocessed-path'
}
also I saw some examples where guys recommend to use construction for tasks
outputs.upToDateWhen { false }
I think outputs.upToDateWhen { false }
works!
The java-comment-preprocessor folder gets regenerated after every clean.
I'm not sure everything works yet since I've got some problems with Kotlin sources thinking they are redeclarations, but I still have some things to try out :).
Thanks!
Okay nice! It works :) thanks!
For future reference, I'll put some examples for projects with Kotlin and Scala code (using gradle kts):
val kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
val preprocessMain by tasks.creating(JcpTask::class) {
sources.set(kotlinMainSources)
clearTarget.set(true)
fileExtensions.set(listOf("kt"))
vars.set(Versions.versionMap)
outputs.upToDateWhen { target.get().exists() }
}
tasks.compileKotlin {
dependsOn(preprocessMain)
outputs.upToDateWhen {
preprocessMain.outcomingFiles.files.isEmpty()
}
doFirst {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(listOf(preprocessMain.target.get()))
}
}
}
}
doLast {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(kotlinMainSources)
}
}
}
}
}
val scalaMainSources = sourceSets.main.get().scala.sourceDirectories
val preprocessMain by tasks.creating(JcpTask::class) {
sources.set(scalaMainSources)
clearTarget.set(true)
fileExtensions.set(listOf("scala"))
vars.set(Versions.versionMap)
outputs.upToDateWhen { target.get().exists() }
}
tasks.compileScala {
dependsOn(preprocessMain)
outputs.upToDateWhen {
preprocessMain.outcomingFiles.files.isEmpty()
}
doFirst {
scala {
sourceSets {
main {
scala.setSrcDirs(listOf(preprocessMain.target.get()))
}
}
}
}
doLast {
scala {
sourceSets {
main {
scala.setSrcDirs(scalaMainSources)
}
}
}
}
}
Edit: Updated so IntelliJ plays nice by only temporarily changing the source folders. Edit2: Updated again to make intellij not do incremental code changes without jcp
Version 7.0.5, Gradle 7.4
Currently, the default target of the
preprocess
task is "build/java-comment-preprocessor/preprocess". This is inside the build folder, which gets deleted entirely when running theclean
task. However, if I runpreprocess
again after a clean, I get> Task :core:preprocess UP-TO-DATE
, after which, the preprocess folder won't be regenerated anymore. Currently, my solution is to enableclearTarget
and move the target outside of the build folder so it survives aclean
and clears itself. This is not ideal, however.