Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a Maven Mojo that automatically adds new source folders to the build
    primarykey
    data
    text
    <p>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.</p> <p>I am aware of the <code>build-helper-maven-plugin</code> 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 <a href="http://blog.tfd.co.uk/2009/07/29/howto-add-more-than-one-source-directory-into-a-maven-build/" rel="nofollow">20 lines of extra configuration in the pom</a>.</p> <p>I would like to create a mojo that configures the extra source folders automatically.</p> <p>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.</p> <pre><code>/** * @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"); } } </code></pre> <p>Again, my goal is to ensure the <em>minimal</em> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload