Unable to invoke avro-maven plugin

后端 未结 4 1775
星月不相逢
星月不相逢 2021-01-18 21:26

My question is similar to Unable to compile and create .avro file from .avsc using Maven

I have tried all possible things, checked the maven project 100 times, still

相关标签:
4条回答
  • 2021-01-18 21:42

    Below is a sample POM file that I've successfully used. My guess is that your sourceDirectory & outputDirectory tags weren't properly defined...

    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>helloworld</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <properties>
            <!-- Keep Hadoop versions as properties to allow easy modification -->
            <hadoop.version>2.6.0-cdh5.4.0</hadoop.version>
            <avro.version>1.7.7</avro.version>
            <mrunit.version>1.1.0</mrunit.version>
            <!-- Maven properties for compilation -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-client</artifactId>
                <version>${hadoop.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro</artifactId>
                <version>${avro.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-tools</artifactId>
                <version>${avro.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.mrunit</groupId>
                <artifactId>mrunit</artifactId>
                <version>${mrunit.version}</version>
                <classifier>hadoop2</classifier>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <!-- Set the Java target version to 1.7 -->
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.0</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <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>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    
    0 讨论(0)
  • 2021-01-18 21:44

    As mentioned in comments , I put a surrounding <pluginManagement> tag over <plugins> and it resolved issue for me. I am using eclipse Mars. Example :

    <pluginManagement>
                <plugins>
                    <plugin>....</plugin>
                </plugins>
    <pluginManagement>
    
    0 讨论(0)
  • 2021-01-18 21:52

    That eclipse error in pom file doesn't matters. Make sure that your .avsc file has namespace value, where actual file is getting generated.

    {
    "namespace": "com.hadoop.practice.avro",
    "type": "record",
    "name": "StringPair",
    "doc": "A pair of strings",
    "fields": [
        {"name": "left", "type": "string"},
        {"name": "right", "type": "string"}
    ]
    

    }

    StringPair.java get generated under this namespace defined package

    0 讨论(0)
  • 2021-01-18 21:57

    I publish a simple demo which is fully tested and 100% works https://github.com/xmeng1/avro-maven-demo. There are two important things for generating code by using the Avro

    1. The configuration: if we want to generate code when mvn compile or mvn package, we can put configuration under the execution. If we want to generate code when running goal mvn avro:scheme, we need put the configuration to the plugin directly. (the demo includes two type configuration)
    2. The namespace of the scheme file which will decide which package the generate code will belong to. {"namespace": "com.xx.xx.demo", "name": "Foo"}, the Foo.java will be created under the package com.xx.xx.demo
    0 讨论(0)
提交回复
热议问题