jaxb2-maven-plugin
jaxb2-maven-plugin copied to clipboard
Multiple configurations do not look at source parameter
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.
The xsd files can be anything simple.
I have exactly the same problem. The issue seems to occur also with older versions of the plugin (2.1, 2.2, 2.3)
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.