I wanted to write a quick blog because I’ve wasted a full hour figuring out why the imports on the avro-maven-plugin were not working. If you look at the documentation link above, you will see the following configuration example for the avro-maven-plugin.
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.11.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
However, the configuration section in the execution definition was not actually respected. Here’s an example. Notice I changes the source and output directory names to blah and flarp.
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.11.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src/main/blah/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/flarp/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
When I run the avro:schema target with debugging (mvn clean avro:schema -X
), the output of the configuration in the logs do not reflect the changes.
[DEBUG] Configuring mojo 'org.apache.avro:avro-maven-plugin:1.11.0:schema' with basic configurator -->
[DEBUG] (f) createSetters = true
[DEBUG] (f) customConversions = []
[DEBUG] (f) customLogicalTypeFactories = []
[DEBUG] (f) enableDecimalLogicalType = false
[DEBUG] (f) fieldVisibility = PRIVATE
[DEBUG] (f) outputDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/target/generated-sources/avro
[DEBUG] (f) project = MavenProject: com.kubetrade.shared:shared-schema:0.0.1-SNAPSHOT @ /Users/stephennimmo/Projects/github/kubetrade/shared-schema/pom.xml
[DEBUG] (f) sourceDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/src/main/avro
[DEBUG] (f) testOutputDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/target/generated-test-sources/avro
[DEBUG] (f) testSourceDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/src/test/avro
[DEBUG] (f) velocityToolsClassesNames = []
[DEBUG] -- end configuration --
However, when I move the configuration up to the plugin level, it works.
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.11.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/blah/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/flarp/</outputDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
</execution>
</executions>
</plugin>
[DEBUG] Configuring mojo 'org.apache.avro:avro-maven-plugin:1.11.0:schema' with basic configurator -->
[DEBUG] (f) createSetters = true
[DEBUG] (f) customConversions = []
[DEBUG] (f) customLogicalTypeFactories = []
[DEBUG] (f) enableDecimalLogicalType = false
[DEBUG] (f) fieldVisibility = PRIVATE
[DEBUG] (f) outputDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/src/main/flarp
[DEBUG] (f) project = MavenProject: com.kubetrade.shared:shared-schema:0.0.1-SNAPSHOT @ /Users/stephennimmo/Projects/github/kubetrade/shared-schema/pom.xml
[DEBUG] (f) sourceDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/src/main/blah
[DEBUG] (f) testOutputDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/target/generated-test-sources/avro
[DEBUG] (f) testSourceDirectory = /Users/stephennimmo/Projects/github/kubetrade/shared-schema/src/test/avro
[DEBUG] (f) velocityToolsClassesNames = []
[DEBUG] -- end configuration --
I hope this can save someone the hour I just wasted.
Saved me a lot of time, thank you!