I have created a custom Maven plugin like so:
@Mojo(name="generate", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)
public class HandlerGeneratorMojo extends AbstractMojo {
...
}
And I am using it like this:
<!-- GENERATE EVENT HANDLERS (POC) -->
<plugin>
<artifactId>handler-generator-maven-plugin</artifactId>
<groupId>my.group.id</groupId>
<version>${revision}</version>
<executions>
<execution>
<id>generate handlers</id>
<phase>prepare-package</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
In the execute method of the Mojo I am trying to retrieve all interfaces that extend interface CdsData, using the Reflections api.
final Reflections reflections = new Reflections();
final Set<Class<? extends CdsData>> allClasses =
reflections.getSubTypesOf(CdsData.class);
log.info("Number of results: " + allClasses.size());
for (final Class<? extends CdsData> cdsDataClass: allClasses) {
log.info("Result: " + cdsDataClass);
}
I get five results, that are in a dependency of the pom where I execute the plugin. So that is ok. However I have also generated some implementations using another plugin (cds4j-maven-plugin) that has set
<phase>generate-sources</phase>
And I have tried to set the phase of my custom plugin to prepare-package so it is executed way after the above plugin has generated the sources. However I get no more results than the five I mentioned before. I would expect to see those generated interfaces as well.
Might this be a class path, or class loader problem? Or the phases maybe?
I have also tried to put the package of the generated classes in the Reflections constructor, and I have tried to configure Reflections class loading as described here at line 8: https://www.hellojava.com/a/80798.html
Any help is appreciated! Thank you!
Cheers, Kjeld