Why are Maven generated-sources not getting compiled?

If you have written the plugin by yourself you can programatically add the path with the generated sources to the maven source paths.

@Mojo(name = "generate")
public class MyCodegenMojo extends AbstractMojo {
    @Parameter(defaultValue = "${project}")
    private MavenProject project;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException{
        // your generator code

        project.addCompileSourceRoot("path/to/your/generated/sources");
    }

}

For example the raml-jaxrs-codegen plugin uses this technique. See RamlJaxrsCodegenMojo.java for more details.


The build-helper plugin indeed solved the problem. Thanks @Joe for the comment.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources/wrappers</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>