Can't get QueryDsl / APT to generate Q classes

让人想犯罪 __ 提交于 2019-12-23 23:07:46

问题


I'm trying to use QueryDsl in a new Spring project. I'm new to QueryDsl, and pretty new to maven and Spring, so I may be missing something fairly basic, but I can't get QueryDsl / maven-apt-plugin to generate my Q classes. The Querydsl reference makes sound so easy; I think I did exactly what it said:

I configured pom.xml with:

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

and:

<repository>
  <id>QUERYDSL</id>
  <url>http://source.mysema.com/maven2/releases</url>
  <layout>default</layout>
</repository>

and:

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>2.5.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>

I have two @Entity's in that project.

mvn clean install does not result in any output to target/generated-sources/java/

What am I missing?

I tried mvn apt:process, and it results in:

[ERROR] Failed to execute goal com.mysema.maven:maven-apt-plugin:1.0.3:process (default-cli) on project logging-implementation: Either processor or processors need to be given -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.mysema.maven:maven-apt-plugin:1.0.3:process (default-cli) on project logging-implementation: Either processor or processors need to be given
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)

Any suggestions?

Thanks!


回答1:


OK, I got it. I don't understand it (I'm a Maven noob), but here's what worked: In the parent pom.xml, I have

<build>
  <pluginManagement>
    <plugins> 
      the maven-apt-plugin definition shown above 
    </plugin>
  <pluginManagement>
</build>

and in the project's POM I have:

<build>
    <plugins> 
      the **exact same** maven-apt-plugin definition shown above 
    </plugin>
</build>

without the <pluginManagement> level betweeen <build> and <plugins>, following the instructions at http://mojo.codehaus.org/apt-maven-plugin/plugin-info.html




回答2:


You are calling the goal directly, but the configuration is execution specific. So either use apt via the standard maven lifecycle or make the configuration general.



来源:https://stackoverflow.com/questions/10746010/cant-get-querydsl-apt-to-generate-q-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!