18 Ocak 2021 Pazartesi

Avro Maven Plugin

Giriş
Çalıştırmak için şöyle yaparız
mvn clean generate-sources
Goals
Avro dosyalarından java kodu üretmek içindir. goal olarak
- schema
- protocol
- idl-protocol
verilebilir.
Açıklaması şöyle
The following goals are available:

schema: Generates Java code from Avro schemas.
protocol: Generates Java code from Avro protocols.
idl-protocol: Generates IDL code from Avro protocols.
idl: Generates IDL code from Avro schemas.

The schema goal is the most commonly used goal. It generates Java code that can be used to read and write Avro data. The protocol goal generates Java code that can be used to communicate with Avro services. The idl-protocol goal generates IDL code that can be used to communicate with Avro services from other languages. The idl goal generates IDL code from Avro schemas.
schema Goal
Örnek
Şöyle yaparız. avro dosyaları src/main/avro s dizini altında
<plugins>
  <plugin>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-maven-plugin</artifactId>
    <version>${avro.version}</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>
</plugins>
Örnek
Şöyle yaparız. avro dosyaları "src/main/resources" dizini altında
<plugins>
  <plugin>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-maven-plugin</artifactId>
    <version>${avro.version}</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <goals>
  <goal>schema</goal>
         </goals>
        <configuration>
          <sourceDirectory>${project.basedir}/src/main/resources</sourceDirectory>
          <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

protocol Goal
Örnek
Şöyle yaparız. avro dosyaları "src/main/resources/avro" dizini altında. Ancak çıktılar target dizini altında yazılıyor.
<properties>
  <avro.version>1.10.1</avro.version>
 </properties>

<plugin>
  <groupId>org.apache.avro</groupId>
  <artifactId>avro-maven-plugin</artifactId>
  <version>${avro.version}</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>schema</goal>
          <goal>protocol</goal>
          <goal>idl-protocol</goal>
      </goals>
      <configuration>
        <sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory>
        <stringType>String</stringType>
        <createSetters>false</createSetters>
        <enableDecimalLogicalType>true</enableDecimalLogicalType>
        <fieldVisibility>private</fieldVisibility>
      </configuration>
    </execution>
    </executions>
</plugin>
"target/generated-sources/avro/source" dizinini de source olarak almak için şöyle yaparız
<plugin>
<groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>target/generated-sources/avro</source> </sources> </configuration> </execution> </executions> </plugin>

Hiç yorum yok:

Yorum Gönder