mojohaus / jaxb2-maven-plugin

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

Multiple configurations do not look at source parameter #89

Open inthegarage opened 7 years ago

inthegarage commented 7 years ago

Using the latest plugin 2.3.1

Given the following configuration:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-import</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <addGeneratedAnnotation>true</addGeneratedAnnotation>
                            <packageName>com.mygroup.model.published</packageName>
                            <outputDirectory>target/generated-sources</outputDirectory>
                            <encoding>UTF-8</encoding>
                            <sources>
                                <source>${project.basedir}/src/main/resources/xsd/publish/publish.xsd</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-publish</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <addGeneratedAnnotation>true</addGeneratedAnnotation>
                            <packageName>com.mygroup.model.imported</packageName>
                            <outputDirectory>target/generated-sources</outputDirectory>
                            <encoding>UTF-8</encoding>
                            <sources>
                                <source>${project.basedir}/src/main/resources/xsd/import/import.xsd</source>
                            </sources>
                            <clearOutputDir>false</clearOutputDir>
                        </configuration>
                    </execution>
                </executions>

            </plugin>

The source configuration is not found, and an error is seen on the console:

Ignored given or default sources [C:\workspaces\project\src\main\xsd], since it is not an existent file or directory.

If I have the following config:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-import</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>

                    </execution>
                </executions>
                <configuration>
                    <addGeneratedAnnotation>true</addGeneratedAnnotation>
                    <packageName>com.mygroup.model.published</packageName>
                    <outputDirectory>target/generated-sources</outputDirectory>
                    <encoding>UTF-8</encoding>
                    <sources>
                        <source>${project.basedir}/src/main/resources/xsd/publish/publish.xsd</source>
                    </sources>
                </configuration>
            </plugin>

Then that single one is generated fine. The plugin is not observing the source directive when there are multiple configurations. This is only picked up when the configuration is outside of the execution body, IE a global configuration.

inthegarage commented 7 years ago

The xsd files can be anything simple.

luciano-fiandesio commented 7 years ago

I have exactly the same problem. The issue seems to occur also with older versions of the plugin (2.1, 2.2, 2.3)

aroneous commented 5 years ago

If you are running the jaxb2:xjc goal directly rather than running it via the generate-sources lifecycle phase (to which the xjc goal is bound by default), note that it will run by default an execution named default-cli. If not explicitly declared, it will use default values, inheriting the plugin-wide configuration. So, in the simple case it would not be referencing your generate-import execution at all, but it works because the settings in there aren't needed.

If the configuration is defined as part of the named executions, and not global, running the default-cli execution will not find any configuration to apply, and will use defaults, hence the issue.

To explicitly run the goal in the context of another execution, you can run:

mvn jaxb2:xjc@generate-import
mvn jaxb2:xjc@generate-publish

More info here.