Does maven-compiler-plugin consider dependencies when checking for stale sources?

496 Views Asked by At

Ant's depend task allows one to recompile Java source-code if any of its dependencies (referenced classes, not module dependencies) have been modified. I took a quick look at org.apache.maven.plugin.CompilerMojo and org.codehaus.plexus.compiler.util.scan.StaleSourceScanner and by the looks of it, they don't take dependencies into account at all. It looks as if source-code gets recompiled if its timestamp is newer than that of the class file (plus some delta).

Did I miss anything or is Maven disregarding the case where the source-code didn't change but its dependency did (hence they both need to be recompiled)?

2

There are 2 best solutions below

1
On

You did not miss anything. Maven is disregarding that case. You'll have to work around it with a clean build.

The maven-versions-plugin can check whether newer versions are available, so there's half the equation. The clean rebuild is still manual work.

0
On

I use the maven-antrun-plugin. There you can configure it. I don't think it is automatic though. What I mean in you have to specify is manually first time you compile it. After wards maven handles your problem.