Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCP is not Gradle clean aware #43

Open
Jolanrensen opened this issue Jun 27, 2022 · 4 comments
Open

JCP is not Gradle clean aware #43

Jolanrensen opened this issue Jun 27, 2022 · 4 comments
Assignees

Comments

@Jolanrensen
Copy link

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.

@raydac
Copy link
Owner

raydac commented Jun 28, 2022

could you try construction, may be it can help

clean {
    delete 'preprocessed-path'
}

@raydac raydac self-assigned this Jun 28, 2022
@raydac
Copy link
Owner

raydac commented Jun 28, 2022

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

outputs.upToDateWhen { false }

@Jolanrensen
Copy link
Author

Jolanrensen commented Jun 28, 2022

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
Copy link
Author

Jolanrensen commented Jun 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants