Repository navigation
bugfix: Keep coverage data in the class directory on sbt 2 - #697
Open
phdoerfler wants to merge 1 commit into
Open
phdoerfler wants to merge 1 commit into
phdoerfler wants to merge 1 commit into
Conversation
tgodzik
requested changes
Oct 19, 2026
tgodzik
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the contribution! Looks like the tests are failing when Scala 3.8.x is used on JDK 8. Not sure if there is a way to run specific test only on sbt 2, so maybe we can just run it on 2.13 (we are not really testing Scala versions itself here)
| @@ -0,0 +1,16 @@ | |||
| version := "0.1" | |||
| scalaVersion := "3.8.4" | |||
Contributor
There was a problem hiding this comment.
Looks like we can't run it on JDK 8, but since we are actually testing sbt 2, we can just use Scala 2.13 here.
Suggested change
| scalaVersion := "3.8.4" | |
| scalaVersion := "2.13.18" |
Contributor
There was a problem hiding this comment.
Alternatively, we can check the java version and switch between Scala versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keep coverage data in the class directory on sbt 2
Fixes #696.
On sbt 2,
compileis cached. A cache hit restores only the declared outputs, i.e. the class directory. Thescoverage-datadirectory undercrossTarget(scoverage.coverageplus the directory the instrumented classes write measurements into) is a side effect of compilation, so it is not restored. Afterclean, a fresh checkout, or on a CI agent with a warm cache:FileNotFoundExceptiononscoverage.measurements.*, orcoverageReportlogsNo coverage data, skipping reportsand skips the minimum check.This changes the sbt 2 default of
coverageDataDirtoCompile / classDirectory, the workaround from #696. The sbt 1 default stayscrossTarget. The switch lives inScoverageSbtPluginCompat, next to the existingDef.uncached.Trade-offs:
<classes>/scoverage-reportand<classes>/coverage-report.scoverage-data. A normal compile rewrites the class directory, so regular packaging is unaffected.coverageDataDirthemselves keep their value. The README notes it should stay inside the class directory on sbt 2.An alternative would be to move only
scoverage-datainto the class directory and keep reports undercrossTarget. That needs a separate path for data vs. reports, including incoverageAggregate. I decided against that since both variants have their downsides and the one presented in this PR is at least a very minimal change.The largest change is the addition of a new scripted test.
cached-compilerunsclean; coverage; testOnly; coverageReporttwice withTest / fork := trueand a 100% minimum. On sbt 2 (sbt "++ 3.x" "scripted scoverage/cached-compile"), it fails without the change (FileNotFoundExceptionin round 2) and passes with it. It also passes on sbt 1. Note that CI currently runsscriptedon sbt 1 only.fwiw: with
Test / fork := false, round 2 reports 0% (noted in #696). That looks like a separate in-JVM Invoker issue (#522).