Maven annotation processing with maven-compiler-plugin

我们两清 提交于 2019-12-01 06:39:18

问题


I try to compile my code that contains annotations that generate source code. I use the maven-compiler-plugin and build-helper-maven-plugin. My POM is looking like that:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <generatedSourcesDirectory>${project.build.directory}/generated-sources/apt</generatedSourcesDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources/apt</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

When I run mvn compile, ${project.build.directory}/generated-sources/apt is added as a source directory, and the generated sources are generated in the correct directory. But I get compiler errors because of missing references to the generated classes. It's like the generated source directory is not included in the compilation process.

I also try apt-maven-plugin which does not generate anything. And maven-annotation-plugin but it behaves as describe above.


回答1:


Can you try with the latest version of maven compiler plugin (2.3.2)?

Also build-helper-maven-plugin is not required since it looks like you are using the maven-compiler-plugin itself to generate the sources from the annotation.




回答2:


The release 2.0.7-SNAPSHOT of maven-annotation-plugin should solve the problem




回答3:


fwiw I just downgraded from 3.0 to 2.5.1 and fixed an issue I was seeing with APT processing not being executed after a few runs, using maven so just downgraded one version:

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.apache.maven.plugins%22%20AND%20a%3A%22maven-compiler-plugin%22



来源:https://stackoverflow.com/questions/4941355/maven-annotation-processing-with-maven-compiler-plugin

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