无法将已编译的 java avro 文件导入 Scala 代码库

Unable to import compiled java avro files into Scala codebase

我正在尝试在我的 scala 代码库中引用生成的 Avro 文件。我正在使用 commercehub avro gradle 插件生成 avro java 编译文件,它们在 build/generated-main-avro-java/

中正确生成

这是我的 gradle 文件的样子。问题是 java 文件生成正确,但我无法将它们导入我的 Scala 代码中。知道我在这里做错了什么吗?

buildscript {
    repositories {
        gradlePluginPortal()
    }

    dependencies {
        classpath "gradle.plugin.com.lightbend.akka.grpc:akka-grpc-gradle-plugin:0.7.2"
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
    }
}

plugins {
    id 'scala'
    id 'application'
    id "com.google.protobuf" version "0.8.8"
    id 'com.github.johnrengelman.shadow' version '5.2.0'
    id "com.commercehub.gradle.plugin.avro" version "0.9.1"
}

apply plugin: 'java'
apply plugin: 'com.lightbend.akka.grpc.gradle'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: "com.commercehub.gradle.plugin.avro"

akkaGrpc {
    language = "Scala"
    generateClient = true
    generateServer = true
}

mainClassName = 'com.test.App'

repositories {
    mavenLocal()
    mavenCentral()
    google()
}

tasks.withType(ScalaCompile) {
    ScalaCompileOptions.metaClass.daemonServer = true
    ScalaCompileOptions.metaClass.fork = true
    ScalaCompileOptions.metaClass.useAnt = false
    ScalaCompileOptions.metaClass.useCompileDaemon = false
}

def scalaVersion = "2.12"
ext.elasticAPMVersion = "1.14.0"

// Define a separate configuration for managing the dependency on Jetty ALPN agent.
configurations {
    alpnagent
}

dependencies {
    ...
    ...
    ...
    ...
    ...
    implementation "org.apache.avro:avro:1.9.2"
}

test {
    jvmArgs "-javaagent:" + configurations.alpnagent.asPath
    maxParallelForks = 1
}

run {
    mainClassName = mainClassName
    standardInput = System.in
}

task runServer(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = mainClassName
    jvmArgs "-javaagent:" + configurations.alpnagent.asPath
}

shadowJar {
    classifier = 'shadow'
    mainClassName = mainClassName
    archiveName = "${title}-${version}.jar"
    append 'reference.conf'
    destinationDir new File("./docker/bin")
    zip64 true
}

我想说的是,您需要将生成的源文件夹添加到源集和 Scala 编译器源中 - 如下所示:

compileScala {
    source = ['src/main/scala', 'src/main/java', 'build/generated-main-avro-java/']
}
sourceSets {
    main {
        avro {
            scala.srcDir file('build/generated-main-avro-java/')
        }
    }
}