Search code examples
jaxbmaven-3lifecyclemaven-jaxb2-plugin

jaxb2 goal is not invoked


I am using maven-jaxb2-plugin to generate some classes from xsd. It is defined in child pom as follows:

<pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.8.0</version>
                <executions>
                    <execution>
                        <id>jaxb2-generate</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <forceRegenerate>true</forceRegenerate>
                    <!-- Generate classes from XSD (XML Schema) using JAXB -->
                    <schemaDirectory>src/main/resources/com/reportcenter/settings/</schemaDirectory>
                    <generatePackage>com.reportcenter.settings</generatePackage>
                    <schemaIncludes>
                        <include>**/*.xsd</include>
                    </schemaIncludes>
                    <strict>false</strict>
                    <extension>true</extension>
                    <plugins>
                        <plugin>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-basics</artifactId>
                            <version>0.6.2</version>
                        </plugin>
                        <plugin>
                            <groupId>org.jvnet.jaxb2_commons</groupId>
                            <artifactId>jaxb2-basics-annotate</artifactId>
                            <version>0.6.2</version>
                        </plugin>
                    </plugins>
                    <args>
                        <arg>-Xannotate</arg>
                        <arg>-XtoString</arg>
                        <arg>-Xcopyable</arg>
                    </args>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

The problem is the jaxb2 is not called from mvn install or mvn compile or mv generate-sources. If I call mvn jaxb2:generate (as the name of the goal) the classes are created OK. I looked at some questions here and used the answers provided, but I am still missing something. Thank you.


Solution

  • Disclaimer: I am the author of the maven-jaxb2-plugin.

    Seems like you only configure the plugin in pluginManagement but don't actualy use it in your build part.

    This is how it should look like:

    <project ...>
        ...
        <build>
            <plugins>
                ...
                <plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.12.3</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
        </build>
        ...
    </project>
    

    Few other comments on your configuration:

    • 0.8.0 is a very old version, 0.12.3 is the actual one.
    • With modern Maven you no longer need to configure maven-compiler-plugin with source/target version 1.6.
    • Do not use forceRegenerate.
    • Consider using binding files instead of generatePackage.
    • Current version of jaxb2-basics is 0.9.2.