I have created a new compiler for the maven-compiler-plugin. This compiler likes to look for compile sources in both src/main/groovy and src/main/java. Similarly, test sources are in both src/test/groovy and src/test/java.
I am aware of the build-helper-maven-plugin
that allows users to augment their pom to specify new source folders for a build, but using this plugin is not ideal since it requires more than 20 lines of extra configuration in the pom.
I would like to create a mojo that configures the extra source folders automatically.
Here is the mojo that I have created, but I do not know how to ensure that the mojo is executed at the right time.
/**
* @goal add-groovy-source
* @phase generate-sources
* @requiresDependencyResolution compile
* @execute phase="compile"
*/
public class AddGroovySourceFolders extends AbstractMojo {
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Adding /src/main/groovy to the list of source folders");
this.project.addCompileSourceRoot(project.getBasedir() + "/src/main/groovy");
}
}
Again, my goal is to ensure the minimal amount of configuration in the user's pom. By this I mean that there should only be a declaration of a dependency to the plugin that contains this mojo and no further configuration.