对于 Maven,有一个官方的 Avro 插件可以从 Avro 模式生成 Java 类。
然而,Gradle 不存在官方插件。
有davidmc24/gradle-avro-plugin,但它不再维护,正在寻找维护者。
作为 Gradle 构建的一部分,如何从 Avro 架构生成 Java 类?
我正在使用 apache avro maven 插件,目的是从 avsc 生成 java。我在 m1 mac 上运行这个(虽然我没有在网上看到任何关于这个问题的信息)。
问题似乎是我的配置没有被采纳。代码生成似乎可以使用默认值。例如
它正在寻找 avsc。
Failed to execute goal org.apache.avro:avro-maven-plugin:1.10.2:schema (default-cli) on project falc-proxy: neither sourceDirectory: /Users/pdhulipala/falc-proxy/src/main/avro or testSourceDirectory: /Users/pdhulipala/falc-proxy/src/test/avro are directories
Run Code Online (Sandbox Code Playgroud)
插件详细信息定义如下。
<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/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/resources/java/</outputDirectory>
<imports>
<import>${project.basedir}/src/main/resources/avro/MsgHeader.avsc</import>
<import>${project.basedir}/src/main/resources/avro/Request.avsc</import>
</imports>
<includes>
<include>*.avsc</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
想知道是否有办法调试这个/添加日志记录等。
我正在使用以下Avro模式:
Price-state.avsc
{
"namespace": "com.company.model",
"name": "Product",
"type": "record",
"fields": [
{
"name": "product_id",
"type": "string"
},
{
"name": "sale_prices",
"type": {
"name": "sale_prices",
"type": "record",
"fields": [
{
"name": "default",
"type": {
"name": "default",
"type": "record",
"fields": [
{
"name": "order_by_item_price_by_item",
"type": [
"null",
{
"name": "markup_strategy",
"type": "record",
"fields": [
{
"name": "type",
"type": {
"name": "type",
"type": "enum",
"symbols": ["margin", "sale_price"]
}
}
]
}
]
},
{"name": "order_by_item_price_by_weight", "type": ["null", "string"]},
{"name": "order_by_weight_price_by_weight", "type": ["null", "string"]} …Run Code Online (Sandbox Code Playgroud) 我正在使用 Maven 插件 avro-maven-plugin (1.9.2) 从 AVRO-schema-file (avsc) 生成 Java 类。我定义一个日期字段如下:
{
"name": "inceptionDate",
"type": "int",
"logicalType": "date"
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,它生成一个int而不是Date或LocalDate。
private int inceptionDate;
Run Code Online (Sandbox Code Playgroud)
pom.xml配置定义如下:
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.9.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<dateTimeLogicalTypeImplementation>JSR310</dateTimeLogicalTypeImplementation>
<sourceDirectory>${project.basedir}/src/main/resources/schema/</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/main/java/</outputDirectory>
<stringType>String</stringType>
<fieldVisibility>PRIVATE</fieldVisibility>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗,有什么问题吗?
将“org.apache.avro.generic.GenericRecord”转换为“java.util.Map”的简单方法