you need to use buildhelper-maven-plugin to attach the generated-sources
directory.  Maven does not know that you've generated additional sources.
Most/all of the source generator maven plugins will add the
generated-sources/pluginname folder as an additional source path...
buildhelper is there to allow you to achieve the same from outside of a
plugin.

also, the convention would be to put your code in

${project.build.directory}/generated-sources/xtc/

and not

${project.build.directory}/generated-sources/main/java/

It's no biggie, and it probably will not cause any issues.. unless you hit
the maximum path lengths of windows

2009/7/2 Christopher L Conway <ccon...@cs.nyu.edu>

> My project generates source code using the XTC parser generator
> (http://cs.nyu.edu/rgrimm/xtc/). XTC doesn't have a Maven plugin that
> I'm aware of, so I'm trying to build the parser using an Ant Java
> task, like so:
>
>      <plugin>
>        <artifactId>maven-antrun-plugin</artifactId>
>        <executions>
>          <execution>
>            <phase>generate-sources</phase>
>            <configuration>
>              <tasks>
>                <mkdir
> dir="${project.build.directory}/generated-sources/main/java/" />
>                <java classpath="lib/xtc.jar" classname="xtc.parser.Rats">
>                  <arg line="-in ${project.build.sourceDirectory}" />
>                  <arg line="-out
> ${project.build.directory}/generated-sources/main/java/" />
>                  <arg path="${project.build.sourceDirectory}/Dot.rats" />
>                </java>
>              </tasks>
>              <sourceRoot>
>                ${project.build.directory}/generated-sources/main/java
>              </sourceRoot>
>            </configuration>
>            <goals>
>              <goal>run</goal>
>            </goals>
>          </execution>
>        </executions>
>      </plugin>
>
> The details of what XTC does aren't important: the end result is that
> the above generates Dot.java and places it in
> target/generated-sources/main/java. It works fine.
>
> The problem is that, with this plugin element in my pom.xml, none of
> the Java files in the project get compiled. In a project generated
> using "mvn archetype:create -DgroupId=foo -DartifactId=bar", if I run
> "mvn compile" without the plugin element, I get:
>
> $ mvn compile
> [INFO] Scanning for projects...
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building bar
> [INFO]    task-segment: [compile]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] [resources:resources]
> [INFO] Using default encoding to copy filtered resources.
> [INFO] [compiler:compile]
> [INFO] Compiling 1 source file to
> /home/chris/src/tests/maven/project1/bar/target/classes
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESSFUL
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 1 second
> [INFO] Finished at: Wed Jul 01 18:57:08 EDT 2009
> [INFO] Final Memory: 6M/67M
> [INFO]
> ------------------------------------------------------------------------
>
> Whereas with the plugin element invoking XTC, I get (after a "mvn clean"):
>
> $ mvn compile
> [INFO] Scanning for projects...
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building bar
> [INFO]    task-segment: [compile]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] [antrun:run {execution: default}]
> [INFO] Executing tasks
>    [mkdir] Created dir:
> /home/chris/src/tests/maven/project1/bar/target/generated-sources/main/java
> Rats! Parser Generator, v. 1.14.2, (C) 2004-2008 Robert Grimm
> Processing /home/chris/src/tests/maven/project1/bar/src/main/java/Dot.rats
> ...
>
> The XTC process is not failing, AFAICT.
>
> I've tried other kinds of Ant tasks and they don't interfere with Java
> compilation. For example, if I replace the task element above with an
> echo task
>
>              <tasks>
>                <mkdir
> dir="${project.build.directory}/generated-sources/main/java/" />
>                <echo
> file="${project.build.directory}/generated-sources/main/java/Dot.java">
>                  public class Dot { }
>                </echo>
>              </tasks>
>
> I get
>
> $ mvn compile
> [INFO] Scanning for projects...
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building bar
> [INFO]    task-segment: [compile]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] [antrun:run {execution: default}]
> [INFO] Executing tasks
> [INFO] Executed tasks
> [INFO] Registering compile source root
> /home/chris/src/tests/maven/project1/bar/target/generated-sources/main/java
> [INFO] [resources:resources]
> [INFO] Using default encoding to copy filtered resources.
> [INFO] [compiler:compile]
> [INFO] Compiling 2 source files to
> /home/chris/src/tests/maven/project1/bar/target/classes
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESSFUL
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 2 seconds
> [INFO] Finished at: Wed Jul 01 19:03:34 EDT 2009
> [INFO] Final Memory: 7M/79M
> [INFO]
> ------------------------------------------------------------------------
>
> Obviously there's something I'm not understanding about how Maven
> executes the java task. Is there something simple that I'm doing
> wrong? Is there an alternative way to accomplish this task that I
> should try (perhaps a more "Maven-native" way)?
>
> The full pom.xml is attached.
>
> Regards,
> Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> For additional commands, e-mail: users-h...@maven.apache.org
>

Reply via email to