Search code examples
mavenapache-kafkaavroconfluent-platformconfluent-schema-registry

Having issues with using schema-registry:download


I am using the schema registry download maven from here https://docs.confluent.io/platform/current/schema-registry/develop/maven-plugin.html, but I am not able to download the schema into my local project. Here is my plugin content.

<plugin>
  <groupId>io.confluent</groupId>
  <artifactId>kafka-schema-registry-maven-plugin</artifactId>
  <version>6.1.0</version>
  <configuration>
    <schemaRegistryUrls>
      <param>http://localhost:8081</param>
    </schemaRegistryUrls>
    <outputDirectory>src/main/avro</outputDirectory>
    <subjectPatterns>
      <param>MysqlTest2.oms.locations-value</param>
    </subjectPatterns>
    <subjects/>
  </configuration>
</plugin>

Can someone help with it? After I load the maven changes, should I click “clean” and “package” to make it work? Thank you so much!!


Solution

  • First, make sure you have the plugin repository

    <pluginRepositories>
        <pluginRepository> 
            <id>confluent</id> 
            <name>Confluent</name> 
            <url>https://packages.confluent.io/maven/</url> 
        </pluginRepository> 
    </pluginRepositories>
    

    Then, the plugin has multiple goals, so you need to specify which to run, and wouldn't hurt to bind to the Maven phase before compile

    <plugin>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-schema-registry-maven-plugin</artifactId>
        <version>${confluent.version}</version>
        <executions>
            <execution>
                <id>avro-resources</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>download</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            ...
        </configuration>
    

    You should see output that looks like this in the Maven build

    [INFO] --- kafka-schema-registry-maven-plugin:6.1.0:download (avro-resources) @ project ---
    [INFO] Getting all subjects on schema registry...
    [INFO] Schema Registry has XXX subject(s).
    [INFO] Downloading latest metadata for mySubject-value.
    [INFO] Writing schema for Subject(mySubject-value) to /project/src/main/avro/mySubject-value.avsc.
    

    If you need to get a specific version, then see Maven: downloading files from url and use the /subjects/:name/versions/:number/schema endpoint