0

I have a maven project which uses exec-maven-plugin to generate the java classes into the target/generated-sources. The java classes generated underneath is never compiled during mvn clean install.

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                       <sources>
                 <source>${project.build.directory}/foldername</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <id>add-sources</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <phase>prepare-package</phase>
                    <configuration>
                        <mainClass>mainclass</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Do i have to use MOJO for this?

user2916626
  • 9
  • 1
  • 5
  • @Daniele The maven-source-plugin is not related to that. You should use https://www.mojohaus.org/build-helper-maven-plugin/ and add the source to the compile area... – khmarbaise Dec 14 '19 at 09:28
  • A duplicate of https://stackoverflow.com/questions/23687460/java-maven-exec-maven-plugin-not-executing-on-mvn-clean-install, maybe? – Petr Bodnár Dec 14 '19 at 10:19
  • @khmarbaise thanks for pointing that out- user2916626 can you share the maven project? you should add some configurations for the build-helper-maven-plugin, to add the generated-sources folder to the set being compiled – Daniele Dec 14 '19 at 12:22

1 Answers1

0

Using the build-helper-maven-plugin can be configured like the following:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • i am using codehaus.mojo plugin to execute my java classes into generated-sources in target directory at "prepare-package" phase. Later i wanted to generate the .class files for the java classes – user2916626 Dec 17 '19 at 16:35