UP-TO-DATE-CHECK failed with task modifying the output of another task


I’m using the task compileJava of the java plugin to generate classes. A second task (“jpaEnhance”) that depends on compileJava modifies the generated classes. It is added to the jar task.

Here is the code:

compileJava {...} jpaEnhance { dependsOn compileJava { inputs.dir sourceSets.main.output.classesDir outputs.dir sourceSets.main.output.classesDir doFirst { ... } } jar { dependsOn jpaEnhance }

Now the task compileJava is never evaluated to “UP-TO-DATE” and is executed every time.

I know that I can fix it by adding the actions of jpaEnhance to the task compileJava. But I prefer to separate the actions and I need to call the task jpaEnhance separately.

What can I do else that the update check of compileJava evaluates to “UP-TO-DATE”?

Best Regards

Since you’re writing to the input directory, the ‘input’ files are always changing. I don’t know exactly how the up-to-date check works, but using the same directory for input & output will at least guarantee that the compileJava task always runs.

I would change the location of the output directory and reconfigure the jar task to package the stuff in that.

Thanks for your reply.

But your solution has the disadvantage that I have to copy all the class files to another directory because the action in jpaEnhance just modifies class files. This slows the build process down and extra disk space is needed.

With the limitation of jpaEnhance working on the same class files without a dedicated output directory working the jpaEnhance stuff into the compileJava task (as a doLast action) seems to be the best solution to go with. Otherwise the compileJava task calculates it output when it is finished. Then the jpaEnhance task kicks in and changes its own intput so it will never be up-to-date. As jpaEnhance works on the same directory as compileJava is writing to, the compileJava task will also be out-of-date because its output directory has been modified since it last invocation. Have you checked the impact of doing the copy operation you described? In sum it might be faster than always not being up-to-date.


I think I will add the actions of jpaEnhance to compileJava. Thanks for your help.