2013-04-05 303 views
4

我正在修復使用Querydsl apt的遺留項目。由於某種原因,apt-maven-plugin開始失敗。我發現的唯一解決方法是使用alter ego maven-processor-pluginapt Maven插件無法生成Q類

我重新安裝了maven,eclipse和M2E,並沒有取得太大的成功。 maven-apt-plugin無法在/ target/generated-sources/metamodel下創建Q類。

編輯:從行家加入調試

[DEBUG] Configuring mojo com.mysema.maven:apt-maven-plugin:1.0.8:process from pl 
ugin realm ClassRealm[plugin>com.mysema.maven:apt-maven-plugin:1.0.8, parent: su 
[email protected]] 
[DEBUG] Configuring mojo 'com.mysema.maven:apt-maven-plugin:1.0.8:process' with 
basic configurator --> 
[DEBUG] (s) logOnlyOnError = true 
[DEBUG] (s) outputDirectory = C:\DEV\myproject\mainstuff\mainstuff-jpa\target\generate 
d-sources\metamodel 
[DEBUG] (s) pluginArtifacts = [com.mysema.maven:apt-maven-plugin:maven-plugin: 
1.0.8:, org.sonatype.plexus:plexus-build-api:jar:0.0.7:compile, org.codehaus.ple 
xus:plexus-utils:jar:1.5.8:compile, backport-util-concurrent:backport-util-concu 
rrent:jar:3.1:compile, org.codehaus.plexus:plexus-interpolation:jar:1.11:compile 
, junit:junit:jar:3.8.1:compile] 
[DEBUG] (s) processor = com.mysema.query.apt.jpa.JPAAnnotationProcessor 
[DEBUG] (s) project = MavenProject: com.yreham.mainstuff:mainstuff-jpa:1.0 
@ C:\DEV\myproject\mainstuff\mainstuff-jpa\pom.xml 
[DEBUG] (s) sourceEncoding = ISO-8859-1 
[DEBUG] -- end configuration -- 
[DEBUG] Using build context: org.sonatype.plexus.build.incremental.DefaultBuildC 
[email protected] 
[ERROR] C:\DEV\myproject\mainstuff\mainstuff-jpa\src\main\java\com\yreham\mainstuff\j 
pa\queries\InstancesQuery.java:40: error: cannot find symbol 
import com.yreham.mainstuff.jpa.entity.QCIEntity; 

的配置M2E的一些細節 - Maven的集成爲Eclipse 1.2.0.20120903-1050 org.eclipse.m2e.feature.feature.group Eclipse.org - M2E

Java版本 「1.7.0_15」 的Java(TM)SE運行時環境(建立1.7.0_15-B03) 爪哇熱點(TM)64位服務器VM(構建23.7-B01,混合模式)

(目標版本是Java 1.6)

這裏的老POM XML

<plugin> 
<groupId>com.mysema.maven</groupId> 
<artifactId>apt-maven-plugin</artifactId> 
<version>1.0.8</version> 
<executions> 
<execution> 
    <goals> 
     <goal>process</goal> 
    </goals> 
    <configuration> 
    <outputDirectory>${apt.target.dir}</outputDirectory> 
    processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor> 
    <logOnlyOnError>true</logOnlyOnError> 
    </configuration> 
    </execution> 
</executions> 
</plugin> 

與BSC插件

<plugin> 
<groupId>org.bsc.maven</groupId> 
<artifactId>maven-processor-plugin</artifactId> 
<version>2.0.5</version> 
    <executions> 
    <execution> 
    <id>process</id> 
    <goals> 
     <goal>process</goal> 
    </goals> 
<phase>generate-sources</phase> 
    <configuration> 
    <outputDirectory>${apt.target.dir}</outputDirectory> 
    <processors> 
     <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor> 
    </processors>     
    </configuration> 
    </execution> 
</executions> 
<dependencies> 
    <dependency> 
    <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-jpamodelgen</artifactId> 
     <version>1.2.0.Final</version> 
     </dependency> 
    </dependencies> 
</plugin> 
+0

您是否遇到apt-maven-plugin使用的異常? – 2013-04-06 11:12:36

+0

根據下面的resquest我更新與調試輸出的問題。該插件不會拋出異常,它只會找不到Q *類 – 2013-04-08 12:01:54

+0

您使用哪個Querydsl版本?你也使用Spring Data嗎?如果是,哪個版本? – 2013-04-08 14:01:11

回答

1

原來,這是一個JPA配置問題。我沒有看到它在頂級Querydsl上使用Hibernate層。 由於我們轉移到Eclipse J2EE版本並添加了M2E WTP http://www.eclipse.org/m2e-wtp/,jpa模塊已正確重新配置。

2

請問你的項目構建命令行的新POM?

如果沒有,它最有可能無法在eclipse中建立。

現在如果CLI真的有效,你有沒有試過安裝m2e-apt?它將使得註釋處理成爲eclipse增量構建過程的一部分。有關更多詳細信息,請參見https://github.com/jbosstools/m2e-apt/

+0

我正在更新該問題,因爲它在命令行上也失敗了。 – 2013-04-08 12:02:17