生成.gradle-如何将scoverage与Flink shadowjar自定义渐变依赖项配置一起使用


0

摘要

我有一个Gradle-flinkscala项目,并试图添加Scoverage报告,但是compileScoverageScala任务由于自定义的shadowjar配置而无法找到所有的依赖项。

生成.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任务能够找到它,但是compilescovergescala找不到。

有人知道有没有方法可以显式地告诉Scoverage包含flinkShadowJar配置?我希望其他使用Flink的人以前也遇到过这种情况,并知道如何解决它。

1 答案


0

我得到了Scoverage团队的帮助:https://github.com/scoverage/gradle-scoverage/issues/138

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

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

我来回答

写文章

提问题

面试题