Open barrypitman opened 10 years ago
The apt-amven-plugin does a staleness check https://github.com/mysema/apt-maven-plugin/blob/master/src/main/java/com/mysema/maven/apt/AbstractProcessorMojo.java#L236
Do you use the latest version?
I am using the latest version as far as I can tell - 1.1.1
<!-- for querydsl-generated classes-->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
<includes>
<include>mypackage.**.domain.**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
This is the output from mvn compile
with the apt-maven-plugin enabled (on the second run):
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AcTrack: WebApp 1-DEFAULT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildnumber-maven-plugin:1.2:create (default) @ webapp ---
[INFO] Checking for local modifications: skipped.
[INFO] Updating project files from SCM: skipped.
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify HEAD"
[INFO] Working directory: c:\Users\barry\work\actrack\webapp
[INFO] Storing buildNumber: b2b83c12a7d5d923a454ca6410a400ae85ff1c91 at timestamp: 1390483184473
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify HEAD"
[INFO] Working directory: c:\Users\barry\work\actrack\webapp
[INFO] Storing buildScmBranch: UNKNOWN
[INFO]
[INFO] --- apt-maven-plugin:1.1.1:process (default) @ webapp ---
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 116 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3:compile (default-compile) @ webapp ---
[INFO] Compiling 125 source files to c:\Users\barry\work\actrack\webapp\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.700s
[INFO] Finished at: Thu Jan 23 14:19:51 CET 2014
[INFO] Final Memory: 37M/89M
[INFO] ------------------------------------------------------------------------
This is the output if I comment out the apt-maven-plugin:
$ mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AcTrack: WebApp 1-DEFAULT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildnumber-maven-plugin:1.2:create (default) @ webapp ---
[INFO] Checking for local modifications: skipped.
[INFO] Updating project files from SCM: skipped.
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify HEAD"
[INFO] Working directory: c:\Users\barry\work\actrack\webapp
[INFO] Storing buildNumber: b2b83c12a7d5d923a454ca6410a400ae85ff1c91 at timestamp: 1390483897587
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify HEAD"
[INFO] Working directory: c:\Users\barry\work\actrack\webapp
[INFO] Storing buildScmBranch: UNKNOWN
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 116 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3:compile (default-compile) @ webapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.574s
[INFO] Finished at: Thu Jan 23 14:31:38 CET 2014
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
I'm using apt-maven-plugin version 1.1.3 and the staleness checking doesn't work for me either. Every time the plugin is run the Q classes are regenerated.
@martinkovacik Do you use the apt-maven-plugin with an IDE? The update via a temp folder is only used in incremental mode.
@timowest No I don't use an IDE just command line maven 3.2.3 and apt-maven-plugin 1.1.3. The same happens using maven-compiler-plugin 3.0, 3.1 and 3.2. I tried several versions of maven-compiler-plugin because of the https://jira.codehaus.org/browse/MCOMPILER-209 bug. I don't know if this could be related.
I'm still struggling with this - I wait for apt-maven-plugin to generate the Q classes, and then for the compiler to recompile them, even through they haven't changed.
@timowest , you mentioned that the Q classes won't be re-generated if maven is running in incremental mode. Any idea how I can trigger incremental mode when running maven from the command line?
Plugins like jaxb2-maven-plugin use a "staleFile" to determine when files should be regenerated without requiring that maven is running in incremental mode.
This is not related to https://jira.codehaus.org/browse/MCOMPILER-209 - reverted back to 2.5.1 maven compiler, same thing as with 3.1 and useIncrementalCompilation set to false. Files not changed for months are reprocessed and Q files generated all over again. Note: I don't use includes in apt-maven-plugin configuration.
By looking at your code, seems like buildContext.newScanner(directory, false) does not work as advertised.
Thought to check whether it's up to plexus-utils. But it turns out I got versions 1.5.6, 1.5.8, 1.5.15, 2.0.5 and 2.0.6 in my maven repo. Yep, my app needs them all. Why, I don't know, it's maven wonders:)
Still an issue - I run my applications locally with mvn jetty:run
from the command line, and each time I restart the application, it generates new Q-classes, and then the compiler detects that their timestamps have been updated, so needs to recompile all of them. Not sure if there is any workaround?
I use IntelliJ IDEA, but like I said I run jetty from the command line.
Is there any progress on this? Or a workaround?
I found that the AbstractProcessorMojo
uses the BuildContext.isIncremental
to detect whether it should do an incremental build or not.
But in the latest plexus-build-api-0.0.7.jar that is used by the plugin BuildContext.isIncremental
always returns false. So I'm wondering whether this functionality has ever worked at all?..
plexus-build-api-0.0.7.jar BuildContext:
/**
* Filesystem based non-incremental build context implementation which behaves as if all files
* were just created. More specifically,
*
* hasDelta returns <code>true</code> for all paths
* newScanner returns Scanner that scanns all files under provided basedir
* newDeletedScanner always returns empty scanner.
* isIncremental returns <code>false</code<
* getValue always returns <code>null</code>
*
* @plexus.component role="org.sonatype.plexus.build.incremental.BuildContext"
* role-hint="default"
*/
public class DefaultBuildContext implements BuildContext {
...
public boolean isIncremental() {
return false;
}
...
This seems to work for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/java</generatedSourcesDirectory>
<annotationProcessors>
<annotationProcessor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-Xpkginfo:always</arg>
</compilerArgs>
</configuration>
</plugin>
I seems that every time I run my maven build, the apt-maven-plugin is re-generating the source files that are later compiled. Unfortunately, this means that the compiler must compile those files even if the original source file is unchanged, adding to the build time.
Would it be possible to include a "staleness check", so that the QueryDSL source files are only re-generated if the relevant domain classes files have been modified?
This plugin seems to support something similar: http://mojo.codehaus.org/apt-maven-plugin/examples/configuring-staleness-checking.html
Thanks!