hteast100
hteast100

Reputation: 11

unable to generate source code from avro schema files

I know this topic had been asked several times on this site on other places. I have performed due diligence to make sure the solutions from previous similar questions have been tried. But still I could not make it work. The problem I have is: I could not generate source code from avro schema using maven in Eclipse(neon version with M2E installed). When I tried "mvn clean generate-sources" or "mvn clean compile", the mvn result is success, but no source codes generated in target directory.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-avro10 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-avro10 ---
[INFO] Deleting C:\EclipseWS_forOlderProjects\maven-avro10\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.101 s
[INFO] Finished at: 2018-02-18T20:25:46-05:00
[INFO] Final Memory: 8M/241M
[INFO] ------------------------------------------------------------------------

here is my pom.xml file

<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>Maven-Avro</groupId>
  <artifactId>maven-avro10</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>maven-avro10</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.basedir>C:\EclipseWS_forOlderProjects\maven-avro10</project.basedir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.avro</groupId>
      <artifactId>avro</artifactId>
      <version>1.8.2</version>
    </dependency>

    <dependency>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-tools</artifactId>
    <version>1.8.2</version>
</dependency>

       <dependency>
        <groupId>org.apache.avro</groupId>
        <artifactId>avro-compiler</artifactId>  
        <version>1.8.2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.25</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
  <pluginManagement>
  <plugins>
  <plugin>

  <groupId>org.apache.avro</groupId>
  <artifactId>avro-maven-plugin</artifactId>
  <version>1.8.2</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-compiler-plugin</artifactId>
  <version>3.7.0</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
  </configuration>
</plugin>

</plugins>
</pluginManagement>
</build>

</project>

I tried with my own avro schema definition as well as those from Apache Avro getting started sites. For example I placed the two avsc files in ${project.basedir}\src\main\avro\ user.avsc file

{"namespace": "Maven_Avro.maven_avro10",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": ["int", "null"]},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}

and user1.avsc

{"namespace": "example.avro",
 "type": "record",
 "name": "User1",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": ["int", "null"]},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}

as one of the post I read before mentioning that namespace was the problem he could not generate the source code, unfortunately that post did not explain how the namespace caused the issue and how to change the namespace in schema solves the problem. I have tried update Eclipse project via "maven-> update project...", I also tried to build it outside of Eclipse manually with "mvn generate-sources" or "mvn clean generate-sources", the command line build is all successful, but but just no source code is generated in target directory or any other folders.

Please let me know what I have missed or did wrong so my Eclipse (or command line) mvn build does not generate avro schema java source codes. thanks in advance.

Upvotes: 1

Views: 9238

Answers (1)

Arun
Arun

Reputation: 2480

You've configured your plugins under incorrect element <pluginManagement></pluginManagement>, please remove this element and simply let your plugin be under <plugins> element.

Upvotes: 6

Related Questions