querydsl / apt-maven-plugin

Maven APT plugin
Apache License 2.0
79 stars 41 forks source link

Plugin complain when hand-written code is importing generated class #38

Closed DimitriHautot closed 9 years ago

DimitriHautot commented 9 years ago

Hi,

I have a Java class, ContactPredicates, that import a a generated class, QContact.

When I compile the project (mvn clean compile), the apt-maven-plugin emits an information message (but does its job) when encountering this import statement.

I believe this is misleading. Shouldn't the plugin first generate the code before looking at the hand-written code? (BTW, why does the latter happen?)

Here is my plugin configuration:

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.3</version>
    <executions>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <outputDirectory>target/generated-sources/java</outputDirectory>
                <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
            </configuration>
        </execution>
    </executions>
</plugin>

And here is the output of the command:

11:45:13 /work/RTBF/svn/reptel/reptel-webapp/trunk $ mvnocolor clean compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Repertoire telephonique 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ reptel ---
[INFO] Deleting /work/RTBF/svn/reptel/reptel-webapp/trunk/target
[INFO] 
[INFO] --- apt-maven-plugin:1.1.3:process (default) @ reptel ---
/work/RTBF/svn/reptel/reptel-webapp/trunk/src/main/java/be/rtbf/info/reptel/repository/jpa/ContactPredicates.java:3: cannot find symbol
symbol  : class QContact
location: package be.rtbf.info.reptel.model
import be.rtbf.info.reptel.model.QContact;
                                ^
[INFO] 
[INFO] --- jaxb2-maven-plugin:1.6:schemagen (default) @ reptel ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ reptel ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 60 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ reptel ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 133 source files to /work/RTBF/svn/reptel/reptel-webapp/trunk/target/classes
[WARNING] Note: Some input files use unchecked or unsafe operations.
[WARNING] Note: Recompile with -Xlint:unchecked for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.485 s
[INFO] Finished at: 2015-05-28T11:45:22+02:00
[INFO] Final Memory: 25M/81M
[INFO] ------------------------------------------------------------------------
``

Kindly let me know if I have done something wrong.

Kind regards,

Dimitri
johnktims commented 9 years ago

Hi Dimitri,

I haven't been able to reproduce this error. Would you mind sharing your entities or a basic project?

DimitriHautot commented 9 years ago

Hi John.

Sure, I'm finalizing the squeezing ... :-)

In the meantime, please be informed that I could already pinpoint the problem to be only occurring with Java 6. It is fine with 7 and 8.

DimitriHautot commented 9 years ago

Please find 3 files in here: https://gist.github.com/DimitriHautot/26ee0f6234be112762f1

I'm running with Maven 3.2.3.

johnktims commented 9 years ago

First of all, thank you for pointing out that this only happens with Java 6 and for providing a basic project.

The error message you're seeing occurs because the apt-maven-plugin scans all source files by default, searching for entities. As you pointed out, the plugin is still generating the Q classes correctly, but if you want to get rid of the error you can move ContactPredicates to a different package and add the following:

<configuration>
    ...
    <includes>
        <include>be.rtbf.info.reptel.model</include>
    </includes>
    ...
</configuration>

Unfortunately, you can only provide a package to the <include> directive.

DimitriHautot commented 9 years ago

Thanks a lot John, for the fast & accurate answer!

Indeed, I added the <include /> element to match the package, and it worked fine.

Cheers,

Dimitri