【问题标题】:maven-processor-plugin to ignore undefined symbolsmaven-processor-plugin 忽略未定义的符号
【发布时间】:2014-03-25 12:02:10
【问题描述】:

我有 JPA 2 maven 项目,我想处理源以获得静态元模型。我做了什么我拿了JBoss' static meta model processor 并将它设置为在generate-sources 阶段运行。现在,显然我有一些引用元模型的类,编译本身就很好。但是maven-processor-plugin 本身会产生错误,抱怨它无法从元模型中找到符号,如下所示:

[INFO] --- maven-processor-plugin:2.2.4:process (process) @ ng-grid-java ---
[ERROR] diagnostic: c:\...\service\position\PositionSpecifications.java:13: cannot find symbol
symbol  : class Position_

这是合乎逻辑的,因为它实际上会生成这些类,但这是不正确的,因为它会给原本正确的项目带来错误。还是我用错了?我错过了什么吗?

更新:我已经能够通过使用配置参数outputDiagnostics 来抑制错误输出,但我不确定这是正确的方法。

【问题讨论】:

  • 你能发布你的 pom.xml 吗?

标签: maven jpa-2.0 apt


【解决方案1】:

解决方案可以是使用build-helper-maven-plugin 将生成的类添加到项目类路径中,如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>artifactId</artifactId>
        <groupId>groupId</groupId>
        <version>1.0.0-SNAPSHOT</version>       
    </parent>
    <artifactId>jpa-metamodel-generation</artifactId>

    <dependencies>

        <!-- Hibernate JPA metamodel generator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>1.2.0.Final</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate.javax.persistence</groupId>
                    <artifactId>hibernate-jpa-2.0-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>

            <!-- Plugin to generate JPA metamodel -->
            <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>process-sources</phase>
                        <configuration>
                            <outputDirectory>${project.build.directory}/metamodel</outputDirectory>
                            <processors>
                                <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Build helper plugin to add generated sources to classpath -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/metamodel</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

【讨论】:

    【解决方案2】:

    我已经设置了插件的 phase-s,例如:

    build-helper-maven-plugin --> <phase>process-sources</phase>
    

    maven-processor-plugin --> <phase>compile</phase>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多