Schema Registry Maven Plugin¶
Looking for Schema Management Confluent Cloud docs? You are currently viewing Confluent Platform documentation. If you are looking for Confluent Cloud docs, check out Schema Management on Confluent Cloud.
A Maven plugin for Schema Registry is available to help throughout the development process, with configuration options as listed below.
Tip
There is no official out-of-the-box Gradle plugin available for Schema Registry. However, you can reference any of these plugins in your Maven pom.xml
(Project Object Model file):
- GitHub Imflog Kafka Schema Registry Gradle Plugin
- com.commercehub.gradle.plugin.avro (link to GitHub repository for this plugin is here)
- Maven plugin, used in the pom.xml example file by Avro clients for the Schema Registry Tutorials
configs for all goals¶
Starting with Confluent Platform 7.0.0, the configs
option is available for the Schema Registry Maven
plugin for all goals. You can use configs
to add any valid configuration to
the CachedSchemaRegistryClient
.
The syntax details are:
configs
- Type: Map<String, String>
- Required: false
For example, to set up SSL for the Maven plugin, specify the keystore/truststore location by adding the following configuration to the plugin:
<configuration>
<configs>
<schema.registry.ssl.keystore.location>path-to-keystore.jks</schema.registry.ssl.keystore.location>
<schema.registry.ssl.keystore.password>password</schema.registry.ssl.keystore.password>
<schema.registry.ssl.truststore.location>path-to-truststore.jks</schema.registry.ssl.truststore.location>
<schema.registry.ssl.truststore.password>password</schema.registry.ssl.truststore.password>
</configs>
</configuration>
Note that the schema.registry.
prefix is needed, just like other Schema Registry client configurations for HTTPS.
schema-registry:download¶
The download goal is used to pull down schemas from a Schema Registry server. This plugin is used to download Avro schemas for the requested subjects and write them to a folder on the local file system.
schemaRegistryUrls
Schema Registry URLs to connect to.
- Type: String[]
- Required: true
userInfoConfig
User credentials for connecting to Schema Registry, of the form
user:password
. This is required if connecting to Confluent Cloud Schema Registry.- Type: String[]
- Required: false
- Default: null
outputDirectory
Output directory to write the schemas to.
- Type: File
- Required: true
schemaExtension
The file extension to use for the output file name. This must begin with a ‘.’ character.
- Type: File
- Required: false
- Default: .avsc
subjectPatterns
The subject patterns to download. This is a list of regular expressions. Patterns must match the entire subject name.
- Type: String[]
- Required: true
<plugin>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-maven-plugin</artifactId>
<version>7.1.14</version>
<configuration>
<schemaRegistryUrls>
<param>http://192.168.99.100:8081</param>
</schemaRegistryUrls>
<outputDirectory>src/main/avro</outputDirectory>
<subjectPatterns>
<param>^TestSubject000-(key|value)$</param>
</subjectPatterns>
</configuration>
</plugin>
schema-registry:test-compatibility¶
This goal is used to read schemas from the local file system and test them for compatibility against the Schema Registry server(s). This goal can be used in a continuous integration pipeline to ensure that schemas in the project are compatible with the schemas in another environment.
schemaRegistryUrls
Schema Registry URLs to connect to.
- Type: String[]
- Required: true
userInfoConfig
User credentials for connecting to Schema Registry, of the form
user:password
. This is required if connecting to Confluent Cloud Schema Registry.- Type: String[]
- Required: false
- Default: null
subjects
Map containing subject to schema path of the subjects to be registered.
- Type: Map<String, File>
- Required: true
Tip
Starting with Confluent Platform 5.5.5, you can specify a slash
/
, and other special characters, in a subject name. To do so, first URL-encode the subject name, and then replace non-valid characters in the output. For example, if you have a subject name such aspath/to/my.proto
, the URL encoding would produce something like`%2Fpath%2Fto%2Fmy.proto`
, which you can then revise by replacing%
with_x
as follows:_x2Fpath_x2Fto_x2Fmy.proto
(because%
is not valid in an XML name). The reasoning behind this is that the Maven plugin requires subject names be specified as XML elements, but some characters, like slashes, are not valid characters in an XML name. You might want to use slashes to register a Protobuf schema that is referenced by another schema, such as/path/to/my.proto
for the subject. This workaround enables you to do that.schemaTypes
String that specifies the schema type.
- Type: String (one of
AVRO
(default),JSON
,PROTOBUF
) - Required: false
- Default: AVRO
- Type: String (one of
references
Map containing a reference name and a subject.
- Type: Map<String, Reference[]>
- Required: false
verbose
Include in the output the reason the schema fails the compatibility test, in cases where it fails.
- Type: Boolean
- Required: false
- Default: true
The following example uses the plugin to configure three subjects (order
, product
, and customer
) using schema type: AVRO
<plugin>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-maven-plugin</artifactId>
<version>7.1.14</version>
<configuration>
<schemaRegistryUrls>
<param>http://192.168.99.100:8081</param>
</schemaRegistryUrls>
<subjects>
<order>src/main/avro/order.avsc</order>
<product>src/main/avro/product.avsc</product>
<customer>src/main/avro/customer.avsc</customer>
</subjects>
<schemaTypes>
<order>AVRO</order>
<product>AVRO</product>
<customer>AVRO</customer>
</schemaTypes>
<references>
<order>
<reference>
<name>com.acme.Product</name>
<subject>product</subject>
</reference>
<reference>
<name>com.acme.Customer</name>
<subject>customer</subject>
</reference>
</order>
</references>
</configuration>
<goals>
<goal>test-compatibility</goal>
</goals>
</plugin>
Example Usage¶
Example usage of schema-registry:test-compatibility
:
- to a local Schema Registry, see Schema Registry Tutorials.
- to Confluent Cloud Schema Registry, see GitHub example.
schema-registry:validate¶
This goal is used to read schemas from the local file system and validate them locally, before registering them.
If you find syntax errors, you can examine and correct them before submitting schemas to Schema Registry with schema-registry:register
.
schemaRegistryUrls
Schema Registry URLs to connect to.
- Type: String[]
- Required: true
userInfoConfig
User credentials for connecting to Schema Registry, of the form
user:password
. This is required if connecting to Confluent Cloud Schema Registry.- Type: String[]
- Required: false
- Default: null
subjects
Map containing subject to schema path of the subjects to be registered.
- Type: Map<String, File>
- Required: true
schemaTypes
String that specifies the schema type.
- Type: String (one of
AVRO
(default),JSON
,PROTOBUF
) - Required: false
- Default: AVRO
- Type: String (one of
references
Map containing a reference name and a subject.
- Type: Map<String, Reference[]>
- Required: false
schema-registry:register¶
This goal is used to read schemas from the local file system and register them on the target Schema Registry server(s). This goal can be used in a continuous deployment pipeline to push schemas to a new environment.
schemaRegistryUrls
Schema Registry URLs to connect to.
- Type: String[]
- Required: true
userInfoConfig
User credentials for connecting to Schema Registry, of the form
user:password
. This is required if connecting to Confluent Cloud Schema Registry.- Type: String[]
- Required: false
- Default: null
subjects
Map containing subject to schema path of the subjects to be registered.
- Type: Map<String, File>
- Required: true
schemaTypes
String that specifies the schema type.
- Type: String (one of
AVRO
(default),JSON
,PROTOBUF
) - Required: false
- Default: AVRO
- Type: String (one of
normalizeSchemas
Normalizes schemas based on semantic equivalence during registration or lookup. To learn more, see Schema Normalization in Formats, Serializers, and Deserializers.
- Type: Boolean
- Required: false
- Default: false
references
Map containing a reference name and a subject.
- Type: Map<String, Reference[]>
- Required: false
The following example uses the plugin to configure three subjects (order
, product
, and customer
) using schema type: AVRO
<plugin>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-maven-plugin</artifactId>
<version>7.1.14</version>
<configuration>
<schemaRegistryUrls>
<param>http://192.168.99.100:8081</param>
</schemaRegistryUrls>
<subjects>
<order>src/main/avro/order.avsc</order>
<product>src/main/avro/product.avsc</product>
<customer>src/main/avro/customer.avsc</customer>
</subjects>
<schemaTypes>
<order>AVRO</order>
<product>AVRO</product>
<customer>AVRO</customer>
</schemaTypes>
<references>
<order>
<reference>
<name>com.acme.Product</name>
<subject>product</subject>
</reference>
<reference>
<name>com.acme.Customer</name>
<subject>customer</subject>
</reference>
</order>
</references>
</configuration>
<goals>
<goal>register</goal>
</goals>
</plugin>