Search code examples
mavencastor

Multiple XSD schemas for castor with castor-maven-plugin


Is it possible to work with multiple xsd schemas with castor-maven-plugin simultaneously?

I use it in rotation (schema1 and schema2) in POM and it works:

<build>
    ...
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>castor-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <schema>src/main/castor/schema1.xsd</schema>
                <dest>src/main/java</dest>
                <packaging>com.path.to.schema1.beans</packaging>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

...

with a little problem: mvn:install collects all classes to target except chema2.crd (or schema1 if I use schema2). I have to copy file manually.

Can I fix it? Are there any ways to configure castor-maven-plugin ?


Solution

  • Try using multiple executions like this:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>castor-maven-plugin</artifactId>
        <version>2.1</version>
        <executions>
            <execution>
                <id>firstSchema</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                  <schema>src/main/castor/schema1.xsd</schema>
                  <dest>src/main/java</dest>
                  <packaging>com.path.to.schema1.beans</packaging>
                </configuration>
            </execution>
            <execution>
                <id>secondSchema</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                  <schema>src/main/castor/schema2.xsd</schema>
                  <dest>src/main/java</dest>
                  <packaging>com.path.to.schema2.beans</packaging>
                </configuration>
            </execution>
        </executions>
    </plugin>