mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
105 stars 76 forks source link

Generated sources only added to project if sources need to be regenerated #162

Open tvanhill opened 4 years ago

tvanhill commented 4 years ago

This plugin calls MavenProject.addCompileSourceRoot() and MavenProject.addTestCompileSourceRoot() from AbstractJavaGenreatorMojo.performExecution(). This method is called by AbstractJaxbMojo.execute(). However, the test code is only added if AbstractJaxbMojo.isReGenerationRequired() returns true for the generated test code. This means, that other Maven plugin cannot depend on these source files being available if the generated code is not regenerated in the current Maven run.

As an example pipeline, may perform the following steps.

  1. Verify it Builds - mvn clean install -DskipTests=true
  2. Run Tests and Compute Coverage (using JaCoCo) - mvn test -P coverage

It appears that enabling JaCoCo Because Jacoc results in our test source code being recompiled. Because the tests XSDs (or generated sources for that matter) were not modified, the generated test source is not added to the Maven project. Note the current implementation is potentially adding test source code as real source code. This could cause all sorts of other issues.

Please update the plugin to always add the the test source code to the Maven project regardless of whether or not the sources need to recompiled. I believe this can be solved generically by updating the following.

I have attached the updated files that tested with to ensure it solved our issue.

updates.zip