Handling Maven annotations using maven-compiler-plugin

I am trying to compile my code containing annotations that generate the source code. I use maven-compiler-pluginand build-helper-maven-plugin. My POM looks like this:

        <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 start mvn compile, it is ${project.build.directory}/generated-sources/aptadded as the source directory, and the generated sources are generated in the correct directory. But I get compiler errors due to the lack of references to the generated classes. It, as the generated source directory, is not included in the compilation process.

I am also trying apt-maven-plugin, which does not generate anything. And maven-annotation-plugin, but it behaves as described above.

+3
source share
3 answers

maven- (2.3.2)?

build-helper-maven-plugin , , maven-compiler-plugin .

0

2.0.7-SNAPSHOT maven-annotation-plugin

+1

Source: https://habr.com/ru/post/1526130/


All Articles