You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Justin Lee <ev...@gmail.com> on 2011/04/28 03:53:23 UTC

source generating mojo

I have a this mojo that generates java source.  I want maven to compile that
java source but it seems like the java compiler is done before my mojo can
generate its source.    In the mojo's execute() I've tried making this call:
         project.getDynamicCompileSourceRoots().add(generatedSrc); and i've
tried adding to the list given to me via injection
with ${project.compileSourceRoots}.  I'm not sure which is the correct route
(my gut says the second) but all this seems to be done longer after javac is
run anyway.  Any idea how I can get this to run before javac does?
 Currently the mojo extends CompilerMojo and has an @phase of
generate-sources.  For completeness, i'll include the source below.


/**
 * Compiles Mirah source files
 *
 * @goal generate-sources
 * @phase generate-sources
 * @threadSafe
 * @requiresDependencyResolution compile
 */
public class MirahSourcesMojo extends AbstractMirahMojo {
    /**
     * Project instance, needed for attaching the buildinfo file. Used to
add new source directory to the build.
     *
     * @parameter default-value="${project}"
     * @required
     */
    private MavenProject project;
    /**
     * Project instance, needed for attaching the buildinfo file. Used to
add new source directory to the build.
     *
     * @parameter
default-value="${project.build.directory}/generated-sources/mirah"
     * @required
     * @readonly
     */
    private String generatedSrc;

    @Override
    protected File getGeneratedSourcesDirectory() {
        return new File(generatedSrc);
    }

    public void execute() throws MojoExecutionException,
CompilationFailureException {
        compileSourceRoots.add(generatedSrc);
        executeMirahCompiler(generatedSrc, false);
    }
}

Re: source generating mojo

Posted by Justin Lee <ev...@gmail.com>.
Got it!  Had to reconfigure the sample pom a bit.

On Wed, Apr 27, 2011 at 9:53 PM, Justin Lee <ev...@gmail.com> wrote:

> I have a this mojo that generates java source.  I want maven to compile
> that java source but it seems like the java compiler is done before my mojo
> can generate its source.    In the mojo's execute() I've tried making this
> call:          project.getDynamicCompileSourceRoots().add(generatedSrc); and
> i've tried adding to the list given to me via injection
> with ${project.compileSourceRoots}.  I'm not sure which is the correct route
> (my gut says the second) but all this seems to be done longer after javac is
> run anyway.  Any idea how I can get this to run before javac does?
>  Currently the mojo extends CompilerMojo and has an @phase of
> generate-sources.  For completeness, i'll include the source below.
>
>
> /**
>  * Compiles Mirah source files
>  *
>  * @goal generate-sources
>  * @phase generate-sources
>  * @threadSafe
>  * @requiresDependencyResolution compile
>  */
> public class MirahSourcesMojo extends AbstractMirahMojo {
>     /**
>      * Project instance, needed for attaching the buildinfo file. Used to
> add new source directory to the build.
>      *
>      * @parameter default-value="${project}"
>      * @required
>      */
>     private MavenProject project;
>     /**
>      * Project instance, needed for attaching the buildinfo file. Used to
> add new source directory to the build.
>      *
>      * @parameter
> default-value="${project.build.directory}/generated-sources/mirah"
>      * @required
>      * @readonly
>      */
>     private String generatedSrc;
>
>     @Override
>     protected File getGeneratedSourcesDirectory() {
>         return new File(generatedSrc);
>     }
>
>     public void execute() throws MojoExecutionException,
> CompilationFailureException {
>         compileSourceRoots.add(generatedSrc);
>         executeMirahCompiler(generatedSrc, false);
>     }
> }
>
>
>