0

概括

我有一个 Gradle Flink Scala 项目并正在尝试添加 Scoverage 报告,但compileScoverageScala由于自定义影子 jar 配置,该任务无法找到所有依赖项。

构建.gradle

这是构建文件,它遵循 Flink 的 Gradle 示例。唯一的区别是我尝试添加 Scoverage。

// 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 的人之前也遇到过这个问题,并且知道如何解决它。

4

1 回答 1

1

我从 Scoverage 团队获得了一些帮助:https ://github.com/scoverage/gradle-scoverage/issues/138

将此添加到我的 sourceSets 声明中修复了它。

    scoverage.compileClasspath += configurations.flinkShadowJar
    scoverage.runtimeClasspath += configurations.flinkShadowJar
于 2020-05-27T18:38:24.240 回答