java-comment-preprocessor icon indicating copy to clipboard operation
java-comment-preprocessor copied to clipboard

JCP is not Gradle clean aware

Open Jolanrensen opened this issue 3 years ago • 4 comments

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 the clean task. However, if I run preprocess 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 enable clearTarget and move the target outside of the build folder so it survives a clean and clears itself. This is not ideal, however.

Jolanrensen avatar Jun 27 '22 11:06 Jolanrensen

could you try construction, may be it can help

clean {
    delete 'preprocessed-path'
}

raydac avatar Jun 28 '22 09:06 raydac

also I saw some examples where guys recommend to use construction for tasks

outputs.upToDateWhen { false }

raydac avatar Jun 28 '22 09:06 raydac

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!

Jolanrensen avatar Jun 28 '22 10:06 Jolanrensen

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

Jolanrensen avatar Jun 28 '22 12:06 Jolanrensen