Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Add support for staleness checking #24

Open
barrypitman opened this issue Jan 17, 2014 · 11 comments
Open

Add support for staleness checking #24

barrypitman opened this issue Jan 17, 2014 · 11 comments

Comments

@barrypitman
Copy link

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!

@timowest
Copy link
Member

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?

@barrypitman
Copy link
Author

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] ------------------------------------------------------------------------

@martinkovacik
Copy link

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.

@timowest
Copy link
Member

@martinkovacik Do you use the apt-maven-plugin with an IDE? The update via a temp folder is only used in incremental mode.

@martinkovacik
Copy link

@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.

@barrypitman
Copy link
Author

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.

@jalmasi
Copy link

jalmasi commented Oct 19, 2015

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:)

@barrypitman
Copy link
Author

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.

@michbeck100
Copy link

Is there any progress on this? Or a workaround?

@tfactor2
Copy link

tfactor2 commented Oct 1, 2018

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?..

if (buildContext.isIncremental() && (includedFiles == null || includedFiles.length == 0)) {

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;
  }
  ...

@froque
Copy link

froque commented Jun 1, 2020

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>

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

No branches or pull requests

7 participants