maven-processor-plugin to ignore undefined symbols

[亡魂溺海] 提交于 2019-12-24 01:58:08

问题


I've JPA 2 maven project and I want to process sources to have the static meta model. What I did I took JBoss' static meta model processor and set it up to run during generate-sources phase. Now, obviously I have some classes that reference the meta model and compilation itself goes fine. But maven-processor-plugin itself generates errors complaining that it can't find symbols from meta model like this:

[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_

Which is logical because it actually generates these classes, but is not right since it brings errors to an otherwise correct project. Or maybe I'm using it wrong? Am I missing something?

Update: I have been able to inhibit the error output by using configuration parameter outputDiagnostics but I'm not sure that's the right way.


回答1:


The solution could be adding the generated classes to project classpath using the build-helper-maven-plugin, as follows:

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


I have setted the phase-s of the plugins like:

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

and

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


来源:https://stackoverflow.com/questions/22634008/maven-processor-plugin-to-ignore-undefined-symbols

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