mojohaus / jaxb2-maven-plugin

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

Default OutputDirectory not added when compiling generated sources using the release plugin #44

Closed svendiedrichsen closed 8 years ago

svendiedrichsen commented 8 years ago

When you are doing a release using the maven release plugin the default output directory for generated sources 'generated-sources/jaxb' of the jaxb2 plugin does not get promoted as 'generatedSourcesDirectory' to the compiler. Instead the compiler uses the i guess default folder 'generated-source/annotations' which leads to compile errors during release. To work around this you have to set the output directory as 'generated-sources/annotations' on the jaxb2 plugin.

lennartj commented 8 years ago

I'll investigate if other options should be used, but this seems definitely like a bug.

svendiedrichsen commented 8 years ago

I forgot to mention

Thanks very much for your instantanious response. Looking forward for any insight into this. If I can be of any help, please don't hesitate to ask.

Cheers, Sven

tkn777 commented 8 years ago

Is there a workaround or patch available? TIA!

svendiedrichsen commented 8 years ago

Well, I can't imagine anything else than the workaround mentioned above in my initial comment.

lennartj commented 8 years ago

I think the simplest solution is to add the outputDirectory of the XJC to the Maven Project's source directories. This is done whenever...

  1. ... the plugin execution was not skipped, and
  2. ... the outputDirectory (of the XJC or TestXJC goals) exist
StefanPenndorf commented 8 years ago

Still waiting for 2.3 to be released. @lennartj Do you have an idea, when to expect 2.3 release?

@tkn777 Possible workaround using build-helper-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources/jaxb</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
tkn777 commented 7 years ago

From my point of view my issue is fixed with Release 2.3. Thank you very much!!

ams-tschoening commented 6 years ago

35 is referenced as a duplicate of this and I still see #35 in the Axis2 build with the project axis2-metadata and version 2.3.1 of the plugin in the current trunk of Axis2. So it looks like not all problems around this issue are fixed with version 2.3.

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.3.1</version>
            </plugin>

http://mail-archives.apache.org/mod_mbox/axis-java-dev/201709.mbox/<165709498.20170905111249%40am-soft.de>

http://mail-archives.apache.org/mod_mbox/axis-java-dev/201709.mbox/<CADx4_uUREDZC9f%2Bwdi4PydjOgTVsdj44sp5fCdn-%3DZcjVBLrQA%40mail.gmail.com>

The provided workaround fixes the problem for me as well:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-test-sources/jaxb</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
veithen commented 6 years ago

The important point to mention here is that in Axis2 this occurs with the testXjc goal. The problem is that the fix for this issue is incorrect. It always calls addCompileSourceRoot, which is not the right thing to do for testXjc. In fact it incorrectly duplicates logic that already exists elsewhere in the code (but which is skipped when code generation is skipped), instead of just reusing that logic.

Note that the proposed workaround is also incorrect in this particular case: it should use add-test-source instead of add-source. Using add-source in the generate-sources phase will allow the project to build without failure, but it will have the effect of including some of the (potentially stale) test classes into the main artifact of the project.