2012-11-12 15 views
5

मैं avro-gradle-plugin on github का उपयोग करने की कोशिश कर रहा हूं, लेकिन इसे काम करने के लिए कोई भाग्य प्राप्त नहीं हुआ है। क्या किसी के पास कोई नमूना कोड है कि वे इसे कैसे काम करते हैं?avro gradle प्लगइन नमूना उपयोग

उत्तर

5

मुझे पता चला कि इसे स्वयं कैसे करें।

apply plugin: 'java' 
apply plugin: 'avro-gradle-plugin' 

sourceCompatibility = "1.6" 
targetCompatibility = "1.6" 

buildscript { 
    repositories { 
    maven { 
     // your maven repo information here 
    } 
    } 
    dependencies { 
    classpath 'org.apache.maven:maven-artifact:2.2.1' 
    classpath 'org.apache.avro:avro-compiler:1.7.1' 
    classpath 'org.apache.avro.gradle:avro-gradle-plugin:1.7.1' 
    } 
} 

compileAvro.source = 'src/main/avro' 
compileAvro.destinationDir = file("$buildDir/generated-sources/avro") 

sourceSets { 
    main { 
    java { 
     srcDir compileAvro.destinationDir 
    } 
    } 
} 

dependencies { 
    compileAvro 
} 
0

मैं बेहतर काम करने के लिए "com.commercehub.gradle.plugin.avro" Gradle प्लगइन पाया: निम्नलिखित एक टुकड़ा है कि मैं लोगों के रूप में मैंने किया था, जो एक ही समस्या आती है हो सकता है के लिए साझा करना चाहते हैं है। https://github.com/commercehub-oss/gradle-avro-plugin

0

पर

// Gradle 2.1 and later 
plugins { 
    id "com.commercehub.gradle.plugin.avro" version "VERSION" 
} 

// Earlier versions of Gradle 
buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:VERSION" 
    } 
} 
apply plugin: "com.commercehub.gradle.plugin.avro" 

अधिक जानकारी के होने का मूल्यांकन करते एक प्लगइन निम्नलिखित प्रश्न पूछे जाने की आवश्यकता है:

folllowing का उपयोग

  • उत्पन्न कर रहे हैं फ़ाइलों स्रोत जार में शामिल?
  • प्लगइन तेजी से है? प्रत्येक फ़ाइल के लिए वीएम को फोर्क करने के बजाए अच्छी प्लगइन का उपयोग एवरो टूल्स एपीआई। प्रत्येक फ़ाइल के लिए वीएम बनाने वाली बड़ी मात्रा में फाइलों के लिए संकलन के लिए 10 मिनट लग सकते हैं।
  • क्या आपको इंटरमीडिएट एवीएससी फाइलों की आवश्यकता है?
  • वृद्धिशील है (यानी सभी फ़ाइलों को पुन: उत्पन्न नहीं करते हैं जब तक कि स्रोतों में से कोई एक परिवर्तित नहीं हो जाता)?
  • जेनरेटेड स्कीमा फ़ाइलों तक पहुंच प्रदान करने के लिए पर्याप्त लचीला प्लगइन है, इसलिए स्कीमा रिपोजिटरी में पंजीकरण स्कीमा जैसे आगे की कार्रवाइयां की जा सकती हैं?

यदि आप प्लगइन से खुश नहीं हैं या अधिक लचीलापन की आवश्यकता है तो प्लगइन के बिना इसे लागू करना आसान है।

// 
// define source and destination 
// 
def avdlFiles = fileTree('src/Schemas').include('**/*.avdl') 
// Do NOT generate into $buildDir, because IntelliJ will ignore files in 
// this location and will show errors in source code 
def generatedJavaDir = "generated/avro/java" 

sourceSets.main.java.srcDir generatedJavaDir 

// 
// Make avro-tools available to the build script 
// 
buildscript { 
    dependencies { 
     classpath group:'org.apache.avro', name:'avro-tools' ,version: avro_version 
    } 
} 

// 
// Define task's input and output, compile idl to schema and schema to java 
// 
task buildAvroDtos(){ 
    group = "build" 

    inputs.files avdlFiles 
    outputs.dir generatedJavaDir 

    doLast{ 
     avdlFiles.each { avdlFile -> 
      def parser = new org.apache.avro.compiler.idl.Idl(avdlFile) 
      parser.CompilationUnit().getTypes().each { schema -> 
       def compiler = new org.apache.avro.compiler.specific.SpecificCompiler(schema) 
       compiler.compileToDestination(avdlFile, new File(generatedJavaDir)) 
      } 
     } 
    } 
} 

// 
// Publish source jar, including generated files 
// 
task sourceJar(type: Jar, dependsOn: buildAvroDtos) { 
    from sourceSets.main.allSource 
    // Package schemas into source jar 
    into("Schemas") { from avdlFiles } 
} 

// Clean "generated" folder upon "clean" task 
clean { 
    delete('generated') 
} 
संबंधित मुद्दे