2

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!!

Shan
  • 177
  • 3
  • 12

2 Answers2

4

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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Thank you, but I get this issue: The POM for io.confluent:kafka-schema-registry-maven-plugin:jar:6.0.1 is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.164 s [INFO] Finished at: 2021-02-12T16:28:45-06:00 [INFO] ------------------------------------------------------------------------ [ERROR] Plugin io.confluent:kafka-schema-registry-maven-plugin:6.0.1 or one of its dependencies – Shan Feb 12 '21 at 22:30
  • Plugin io.confluent:kafka-schema-registry-maven-plugin:6.0.1 or one of its dependencies could not be resolved: Failure to find io.confluent:kafka-schema-registry-maven-plugin:jar:6.0.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information ... – Shan Feb 12 '21 at 22:30
  • You didn't add the confluent maven repo https://stackoverflow.com/a/60907434/2308683 – OneCricketeer Feb 12 '21 at 22:31
  • Could you please take a look at my answers below? I had that maven in my project, but I feel like there is some inconsistency in the pom file. Thank you again! – Shan Feb 12 '21 at 22:40
  • If the repo got added sucessfully, then you shouldn't see it trying to pull from `repo.maven.apache.org/maven2`. since it would be found in the other. – OneCricketeer Feb 12 '21 at 23:50
  • 1
    Hi, thanks for your reply again. It looks like my answer was not good and deleted by someone. I solved that issue by adding this ``` confluent Confluent http://packages.confluent.io/maven/ ``` Solved this issue following https://github.com/confluentinc/schema-registry/issues/630, but not sure why need to add this. Thank you so much! – Shan Feb 14 '21 at 00:42
  • Oh, yes. Repositories block is only for dependencies, sorry forgot. But you need both, actually since you're using the Confluent serializer, and you don't need the maven plugins as dependencies, nor do you need the compiler and Avro plugins listed twice... Your "answer" was deleted because it was a response to my answer, not an answer to your question, so you should have edited the question instead – OneCricketeer Feb 14 '21 at 15:29
  • Understood. Thanks a lot! – Shan Feb 15 '21 at 14:33
0

Apart from attaching the download goal to a maven phase which @OneCricketeer correctly mentions, you can also directly call the download goal of the plugin like the below one:

mvn schema-registry:download
Pooya
  • 531
  • 1
  • 5
  • 10