2

I have a plugin which generates lots of java files (i.e FileA.java, FileB.java) under target folder. I'm using "exec-maven-plugin" to execute my plugin as follows

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-event-beans</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.my.project.generate.GenerateJavaFiles</mainClass>
                        <classpathScope>compile</classpathScope>
                        <arguments>
                            <argument>${basedir}/src/main/resources</argument>
                            <argument>${project.build.directory}/generated-sources/generated</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I want to compile these java files created under ${project.build.directory}/generated-sources/generated without adding them to source and package them in jar

Gaël J
  • 11,274
  • 4
  • 17
  • 32
Waqas Ikram
  • 71
  • 2
  • 6
  • What do you mean by "without adding them to source"? If you want to package the compiled classes in the jar, at some point, you going to have to add them to the build. – Tunaki Oct 19 '15 at 10:55
  • @Tunaki Thanks for your response, I mean is there any way i can skip use of "build-helper-maven-plugin" – Waqas Ikram Oct 19 '15 at 11:24
  • There is a way but it is really painful and complicated: you could invoke javac yourself (and take care of the classpath mess and source files mess). But you should really just use the `build-helper-maven-plugin`, why don't you want to use it? – Tunaki Oct 19 '15 at 11:41

1 Answers1

0

With maven-compiler-plugin you can add your files to the build without adding them to src folder.

Example from doc :

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <includes>
      <include>...</include>
    </includes>
  </configuration>
</plugin>
Gaël J
  • 11,274
  • 4
  • 17
  • 32