如何将scoverage与flink shadowjar自定义gradle依赖项配置一起使用

kupeojn6  于 2021-06-26  发布在  Flink
关注(0)|答案(1)|浏览(719)

摘要

我有一个gradle-flink-scala项目,正在尝试添加scoverage报告,但是 compileScoverageScala 由于自定义的shadow jar配置,任务找不到所有依赖项。

构建.gradle

下面是构建文件,它遵循flink的gradle示例。唯一的区别是我试着加上平均数。

// Here are the plugins I'm using
plugins {
    id 'scala'
    id 'application'
    // shadow plugin to produce fat JARs
    id 'com.github.johnrengelman.shadow' version '5.2.0'
    id "org.scoverage" version "4.0.1"
    id "com.github.maiflai.scalatest" version "0.25"
}
...

// Here's the custom configuration used to build the shadow jar without including the main Flink libraries
configurations {
    flinkShadowJar // dependencies which go into the shadowJar

    // always exclude these (also from transitive dependencies) since they are provided by Flink
    flinkShadowJar.exclude group: 'org.apache.flink', module: 'force-shading'
    flinkShadowJar.exclude group: 'com.google.code.findbugs', module: 'jsr305'
    flinkShadowJar.exclude group: 'org.slf4j'
    flinkShadowJar.exclude group: 'log4j'
}
...

// Here's where the custom configuration is added to the classpath, Scoverage isn't picking these up.
sourceSets {
    main.compileClasspath += configurations.flinkShadowJar
    main.runtimeClasspath += configurations.flinkShadowJar

    test.compileClasspath += configurations.flinkShadowJar
    test.runtimeClasspath += configurations.flinkShadowJar

    javadoc.classpath += configurations.flinkShadowJar
}

以下是生成输出:

$ ./gradlew clean build

> Task :compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :compileScoverageScala FAILED
Pruning sources from previous analysis, due to incompatible CompileSetup.
/Users/david.perkins/dev/wffh/flink-validation-fhir/src/main/scala/com/ibm/watson/health/foundation/hri/flink/FhirValidationJob.scala:6: object core is not a member of package com.ibm.watson.health.foundation.hri.flink
import com.ibm.watson.health.foundation.hri.flink.core.BaseValidationJob
                                                  ^

丢失的包被声明为 flinkShadowJar 附属国。这个 compileScala 任务能够找到它,但是 compileScoverageScala 不能。
有人知道有没有办法明确告诉scoverage包含 flinkShadowJar 配置?我希望其他使用flink的人以前也遇到过这种情况,并且知道如何解决它。

dgjrabp2

dgjrabp21#

我得到了scoverage团队的一些帮助:https://github.com/scoverage/gradle-scoverage/issues/138
将此添加到我的sourceset声明中修复了它。

scoverage.compileClasspath += configurations.flinkShadowJar
    scoverage.runtimeClasspath += configurations.flinkShadowJar

相关问题