xmlbeans 5.1.1 using subdirectories of schema to generate sources in maven

277 Views Asked by At

I'm using Maven 3.9.3 with OpenJDK17 and XmlBeans 5.1.1 and it should generate sources from xsd files in the directory ${project.basedir}/src/main/schema. On top of that there are xsd files in a subdirectory of schema (${project.basedir}/src/main/schema/sub). Unfortunally only the sources from the xsd files in the schema directory are generated, but not the ones in the subfolder.

            <plugin>
                <groupId>org.apache.xmlbeans</groupId>
                <artifactId>xmlbeans</artifactId>
                <version>5.1.1</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <repackage>schemaorg_apache_xmlbeans</repackage>
                    <sourceDir>${project.basedir}/src/main/schema/</sourceDir>
                </configuration>
            </plugin>

How can I include the subdirectory in the source generation?

I tried to add a second line of sourceDir in the condiguration section

<sourceDir>${project.basedir}/src/main/schema/</sourceDir>
<sourceDir>${project.basedir}/src/main/schema/sub</sourceDir>

which had as result, that only the xsd files in the subdirectory were included in the source generation.

I tried to seperate the pathes with comma and semicolon

${project.basedir}/src/main/schema/;${project.basedir}/src/main/schema/sub/

which didn't work. Error Message: Set configuration (='${project.basedir}/src/main/schema/;${project.basedir}/src/main/schema/mcm/') to a valid directory containing .xsd,.wsdl files.

My workaround for the time is to change the structure of the project. By creating a child module I can run xmlbeans two times. The child module generates sources from the xsd files in the subfolder with the target directory of the generate-sources folder in the main module.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>5.1.1</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <sourceDir>(mainroot)\src\main\schema\schema  \sub</sourceDir>
                <javaTargetDir>(mainroot)\target\generated-sources</javaTargetDir>
                <classTargetDir>(mainroot)\target\generated-resources</classTargetDir>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                    <version>2.18.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

To make it work I have to run mvn clean and mvn package in two steps. Otherwise the target folder of the main module is deleted after the generated sources from the child are copied (because order is child clean -> child package -> main clean -> main package).

0

There are 0 best solutions below