无法将编译后的java avro文件导入scala代码库

wztqucjr  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(376)

我试图在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
}
9wbgstp7

9wbgstp71#

我想说的是,您需要将generated sources文件夹添加到source set和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/')
        }
    }
}

相关问题