Skip to content

Use Separate Target Directories for Separate Executions

Lyle Hanson edited this page Aug 31, 2015 · 3 revisions

Use Separate Target Directories for Separate Executions

You may want to configure several executions of the maven-jaxb2-plugin in your pom.xml:

<plugin>
	<groupId>org.jvnet.jaxb2.maven2</groupId>
	<artifactId>maven-jaxb2-plugin</artifactId>
	<executions>
		<execution>
			<id>a</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<schemaDirectory>src/main/resources/a</schemaDirectory>						
				<generatePackage>a</generatePackage>
				<generateDirectory>${project.build.directory}/generated-sources/xjc-a</generateDirectory>
			</configuration>
		</execution>
		<execution>
			<id>b</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<schemaDirectory>src/main/resources/b</schemaDirectory>						
				<generatePackage>b</generatePackage>
				<generateDirectory>${project.build.directory}/generated-sources/xjc-b</generateDirectory>
			</configuration>
		</execution>
	</executions>
</plugin>

If you do this, you'll have to configure separate generateDirectory for each of the executions.

The reason behind this are the up-to-date-checks. The plugin creates a list of the "source" and "destination" files and if "source" files were not changed later than the "destination" files, no new generation will be performed.

Now, if both executions are configured with the same target directory, the second execution will not be performed. The plugin will think that "destination" files (actually from the first execution) are newer that the "source" files of the second execution.

Unfortunatelly, there is no better reliable way to check earliest timestamps of the "destination" files. If several executions are generated in the same directory, there is no way for the plugin to tell files from each of the executions apart.

Therefore, if you decide to configure several executions, make sure you configure different generateDirectorys as well.

Next, multiple executions are often used to generate different package per schema via the generatePackage element. This is normally a bad practice. Consider configuring target packages in binding files instead.

See the following issues for more information and discussion:

Clone this wiki locally