maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff MAURY <jeffma...@jeffmaury.com>
Subject Re: writing a maven plugin that transparently adds a new source folder
Date Sat, 26 Nov 2011 17:59:07 GMT
If you need to add source folders, there is an existing Maven plugin to do
it: the build-helper-maven-plugin. Check the doc at
http://mojo.codehaus.org/build-helper-maven-plugin

Regards
Jeff MAURY

On Sat, Nov 26, 2011 at 1:58 AM, Stephen Connolly <
stephen.alan.connolly@gmail.com> wrote:

> either mandate a parent pom... they will have to reference your plugin in
> their pom and the execution from the pluginmgmt will be pulled in, or
> custom lifecycle (they will need to ref the plugin and set extensions to
> true...
>
> themselves the only two ways to skin the cat
>
> - Stephen
>
> ---
> Sent from my Android phone, so random spelling mistakes, random nonsense
> words and other nonsense are a direct result of using swype to type on the
> screen
> On 25 Nov 2011 22:17, "Andrew Eisenberg" <andrew.eisenberg@gmail.com>
> wrote:
>
> > Hi all,
> >
> > I am trying to create a maven plugin that transparently adds a new
> > source folder to the project.  It is always the same folder and so
> > there should be no configuration required from the user.  I've been
> > going through
> > http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html
> > , but I can't find anything that solves my problem.
> >
> > I created a plugin project with the following mojo:
> >
> >
> > /**
> >  * @goal add-xxx-source
> >  * @phase 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/xxx to the list of source
> folders");
> >        this.project.addCompileSourceRoot(project.getBasedir() +
> > "/src/main/xxx");
> >    }
> > }
> >
> > Now, the only way that I can get this mojo executing is by explicitly
> > adding it in the executions section of the plugin dependency:
> >
> >                        <plugin>
> >                                <groupId>org.codehaus.groovy</groupId>
> >                                <artifactId>xxx-compiler</artifactId>
> >                                <version>2.6.0-01-SNAPSHOT</version>
> >                                <executions>
> >                                        <execution>
> >                                                <id>add-source</id>
> >
> >  <phase>generate-sources</phase>
> >                                                <goals>
> >
> >  <goal>add-xxx-source</goal>
> >                                                </goals>
> >                                        </execution>
> >                                </executions>
> >                        </plugin>
> >
> > I would like it so that consumers of my plugin can leave out the
> > extensions section and have the mojo executed automatically, like
> > this:
> >
> >                        <plugin>
> >                                <groupId>org.codehaus.groovy</groupId>
> >                                <artifactId>xxx-compiler</artifactId>
> >                                <version>2.6.0-01-SNAPSHOT</version>
> >                        </plugin>
> >
> > Is this possible? And how can I do this?
> >
> > thanks for your help.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>



-- 
"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message