github.com/apache/beam/sdks/v2@v2.48.2/java/extensions/avro/build.gradle (about)

     1  import java.util.stream.Collectors
     2  
     3  /*
     4   * Licensed to the Apache Software Foundation (ASF) under one
     5   * or more contributor license agreements.  See the NOTICE file
     6   * distributed with this work for additional information
     7   * regarding copyright ownership.  The ASF licenses this file
     8   * to you under the Apache License, Version 2.0 (the
     9   * License); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *     http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an AS IS BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   */
    20  
    21  plugins { id 'org.apache.beam.module' }
    22  applyJavaNature(
    23      automaticModuleName: 'org.apache.beam.sdk.extensions.avro',
    24      disableLintWarnings: ['rawtypes'], // Avro-generated test code has raw-type errors
    25      publish: true,
    26      exportJavadoc: true,
    27  )
    28  applyAvroNature()
    29  
    30  description = "Apache Beam :: SDKs :: Java :: Extensions :: Avro"
    31  
    32  def avroVersions = [
    33      '192' : "1.9.2",
    34      '1102': "1.10.2",
    35      '1111': "1.11.1",
    36  ]
    37  
    38  avroVersions.each { k, v -> configurations.create("avroVersion$k") }
    39  
    40  // Exclude tests that need a runner
    41  test {
    42    systemProperty "beamUseDummyRunner", "true"
    43    useJUnit {
    44      excludeCategories "org.apache.beam.sdk.testing.NeedsRunner"
    45    }
    46  }
    47  
    48  dependencies {
    49    implementation library.java.byte_buddy
    50    implementation library.java.vendored_guava_26_0_jre
    51    implementation(project(path: ":sdks:java:core", configuration: "shadow")) {
    52      // Exclude Avro dependencies from "core" since Avro support moved to this extension
    53      exclude group: "org.apache.avro", module: "avro"
    54    }
    55    implementation library.java.error_prone_annotations
    56    implementation library.java.avro
    57    implementation library.java.joda_time
    58    testImplementation(project(path: ":sdks:java:core", configuration: "shadowTest")) {
    59      // Exclude Avro dependencies from "core" since Avro support moved to this extension
    60      exclude group: "org.apache.avro", module: "avro"
    61    }
    62    testImplementation library.java.avro_tests
    63    testImplementation library.java.junit
    64    testRuntimeOnly project(path: ":runners:direct-java", configuration: "shadow")
    65    testRuntimeOnly library.java.slf4j_jdk14
    66    avroVersions.each {
    67      "avroVersion$it.key" "org.apache.avro:avro:$it.value"
    68      "avroVersion$it.key" "org.apache.avro:avro-tools:$it.value"
    69    }
    70  }
    71  
    72  avroVersions.each { kv ->
    73    configurations."avroVersion$kv.key" {
    74      resolutionStrategy {
    75        force "org.apache.avro:avro:$kv.value"
    76      }
    77    }
    78  
    79    sourceSets {
    80      "avro${kv.key}" {
    81        java {
    82          srcDirs "build/generated/sources/avro${kv.key}/test/java"
    83        }
    84  
    85        compileClasspath = configurations."avroVersion$kv.key" + sourceSets.test.output + sourceSets.test.compileClasspath
    86        runtimeClasspath += compileClasspath + sourceSets.test.runtimeClasspath
    87      }
    88    }
    89  
    90    "compileAvro${kv.key}Java" {
    91      checkerFramework {
    92        skipCheckerFramework = true
    93      }
    94    }
    95  
    96    "spotbugsAvro${kv.key}" {
    97      ignoreFailures = true
    98    }
    99  
   100    "generateAvro${kv.key}AvroJava" {
   101      dependsOn "generateAvroClasses${kv.key}"
   102    }
   103  
   104    task "avroVersion${kv.key}Test"(type: Test) {
   105      group = "Verification"
   106      description = "Runs Avro extension tests with Avro version $kv.value"
   107      outputs.upToDateWhen { false }
   108      classpath = sourceSets."avro${kv.key}".runtimeClasspath
   109  
   110      include '**/*.class'
   111      exclude '**/AvroIOTest$NeedsRunnerTests$*.class'
   112  
   113      dependsOn "generateAvroClasses${kv.key}"
   114    }
   115  
   116    task "generateAvroClasses${kv.key}"(type: JavaExec) {
   117      group = "build"
   118      description = "Generate Avro classes for Avro version $kv.value"
   119      classpath = configurations."avroVersion$kv.key"
   120      main = "org.apache.avro.tool.Main"
   121      args = [
   122          "compile",
   123          "schema",
   124          "src/test/avro/org/apache/beam/sdk/extensions/avro/io/user.avsc",
   125          "src/test/avro/org/apache/beam/sdk/extensions/avro/schemas/test.avsc",
   126          "build/generated/sources/avro${kv.key}/test/java"
   127      ]
   128    }
   129  }
   130  
   131  task avroVersionsTest {
   132    group = "Verification"
   133    description = 'Runs Avro extension tests with different Avro API versions'
   134    dependsOn createTaskNames(avroVersions, "Test")
   135  }
   136  
   137  static def createTaskNames(Map<String, String> prefixMap, String suffix) {
   138    return prefixMap.keySet().stream()
   139        .map { version -> "avroVersion${version}${suffix}" }
   140        .collect(Collectors.toList())
   141  }