Skip to content

Scoverage2 #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,17 @@ scoverage {
}
```

### Run without normal compilation

By default, running any of the plugin tasks will compile the code both using "normal" compilation (`compileScala`)
and using the scoverage scalac plugin (`compileScoverageScala`).

In cases where you only wish to generate reports / validate coverage, but are not interested in publishing the code,
it is possible to only compile the code with the scoverage scalac plugin, thus reducing build times significantly.
In order to do so, simply add the arguments `-PscoverageCompileOnly` to the gradle execution.
For example: `gradle reportScoverage -PscoverageCompileOnly`.

Note that this mode is incompatible with parallel builds in multi-module projects.

### Compatibility with Consistent Versions Plugin

In order for the plugin to work alongside [Palantir's consistent versions plugin](https://github.com/palantir/gradle-consistent-versions),
the Scala version must be manually configured (via `scoverageScalaVersion`); otherwise, the plugin will attempt to
resolve the compilation classpath, which is prohibited by the versions plugin.

Migration to 8.x
----------------

* Running without normal compilation is no longer supported.

Migration to 7.x
----------------

Expand Down
20 changes: 9 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java-gradle-plugin'
id "com.gradle.plugin-publish" version "1.0.0"
id "com.gradle.plugin-publish" version "1.1.0"
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0"
}

Expand All @@ -11,7 +11,7 @@ repositories {
group 'org.scoverage'
description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage'
if (project.version == 'unspecified') {
version = '7.0.0-SNAPSHOT'
version = '8.0.0-SNAPSHOT'
}
ext {
website = 'http://scoverage.org'
Expand All @@ -22,22 +22,19 @@ ext {
}

gradlePlugin {
website = project.ext.website
vcsUrl = project.ext.vcsUrl
description = project.description
plugins {
gradleScoverage {
id = 'org.scoverage'
implementationClass = 'org.scoverage.ScoveragePlugin'
displayName = 'Gradle Scoverage plugin'
tags.set(['coverage', 'scala', 'scoverage'])
}
}
}

pluginBundle {
website = project.website
vcsUrl = ext.vcsUrl
description = project.description
tags = ['coverage', 'scala', 'scoverage']
}

apply plugin: 'maven-publish'
apply plugin: 'groovy'

Expand All @@ -46,7 +43,8 @@ targetCompatibility = '1.8'


dependencies {
compileOnly "org.scoverage:scalac-scoverage-plugin_2.13:1.4.2"
compileOnly "org.scoverage:scalac-scoverage-plugin_2.13.8:2.0.7"
compileOnly "org.scoverage:scalac-scoverage-reporter_2.13:2.0.7"
implementation group: 'commons-io', name: 'commons-io', version: '2.6'

testImplementation 'junit:junit:4.12'
Expand Down Expand Up @@ -116,7 +114,7 @@ gradlePlugin {

task groovydocJar(type: Jar, dependsOn: groovydoc) {
from "$buildDir/docs/groovydoc"
classifier 'groovydoc'
archiveClassifier.set('groovydoc')
}

def propOrDefault(String property) {
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions src/crossScalaVersionTest/java/org/scoverage/Scala32Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.scoverage;

public class Scala32Test extends ScalaVersionTest {

public Scala32Test() { super("3_2"); }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
implementation group: 'org.scala-lang', name: 'scala-library', version: "2.12.8"
implementation group: 'org.scala-lang', name: 'scala-library', version: "2.12.17"
testImplementation group: 'org.scalatest', name: "scalatest_2.12", version: scalatestVersion
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
implementation group: 'org.scala-lang', name: 'scala-library', version: "2.13.1"
implementation group: 'org.scala-lang', name: 'scala-library', version: "2.13.10"
testImplementation group: 'org.scalatest', name: "scalatest_2.13", version: scalatestVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies {
implementation 'org.scala-lang:scala3-library_3:3.2.0'
testImplementation 'org.scalatest:scalatest_3:3.2.14'
testImplementation "org.scalatestplus:junit-4-13_3:3.2.14.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.hello

class World3_2 {

// Scala 3 enum to force Scala 3 (Dotty) compiler
enum Num(val value: String):
case Three extends Num("3")
case Two extends Num("2")

def foo(): String = {
val s = Num.Three.value + Num.Two.value
s
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.hello

import org.junit.runner.RunWith
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class World3_2Suite extends AnyFunSuite {

test("foo") {
new World3_2().foo()
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include '2_12', '2_13'
include '2_12', '2_13', '3_2'
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void reportScoverageOnlyA() {
}

@Test
@Ignore
public void reportScoverageOnlyAWithoutNormalCompilation() {

AssertableBuildResult result = run("clean", ":a:" + ScoveragePlugin.getREPORT_NAME(),
Expand Down Expand Up @@ -192,6 +194,7 @@ public void checkScoverageWithoutCoverageInA() throws Exception {
}

@Test
@Ignore
public void checkScoverageWithoutNormalCompilationAndWithoutCoverageInCommon() throws Exception {

AssertableBuildResult result = runAndFail("clean",
Expand Down Expand Up @@ -254,6 +257,7 @@ public void checkAndAggregateScoverageWithoutCoverageInAll() throws Exception {
}

@Test
@Ignore
public void aggregateScoverageWithoutNormalCompilation() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getAGGREGATE_NAME(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;


Expand Down Expand Up @@ -188,6 +189,7 @@ public void checkScoverageWithoutCoverageInA() throws Exception {
}

@Test
@Ignore
public void checkScoverageWithoutNormalCompilationAndWithoutCoverageInCommon() throws Exception {

AssertableBuildResult result = runAndFail("clean",
Expand Down Expand Up @@ -251,6 +253,7 @@ public void checkAndAggregateScoverageWithoutCoverageInAll() throws Exception {
}

@Test
@Ignore
public void aggregateScoverageWithoutNormalCompilation() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getAGGREGATE_NAME(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

public class ScalaSingleModuleTest extends ScoverageFunctionalTest {
Expand Down Expand Up @@ -100,6 +101,7 @@ public void reportScoverageWithExcludedClasses() throws Exception {
}

@Test
@Ignore
public void reportScoverageWithoutNormalCompilation() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.scoverage;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

public class ScalaSingleModuleWithMultipleTestTasksTest extends ScoverageFunctionalTest {
Expand Down Expand Up @@ -118,6 +119,7 @@ public void reportScoverageWithExcludedClasses() throws Exception {
}

@Test
@Ignore
public void reportScoverageWithoutNormalCompilation() throws Exception {

AssertableBuildResult result = run("clean", ScoveragePlugin.getREPORT_NAME(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private void configureArguments(String... arguments) {
List<String> fullArguments = new ArrayList<>();

fullArguments.add("-PscalaVersionMajor=2");
fullArguments.add("-PscalaVersionMinor=12");
fullArguments.add("-PscalaVersionBuild=8");
fullArguments.add("-PscalaVersionMinor=13");
fullArguments.add("-PscalaVersionBuild=10");
fullArguments.add("-PjunitVersion=5.3.2");
fullArguments.add("-PjunitPlatformVersion=1.3.2");
fullArguments.add("-PscalatestVersion=3.0.8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,35 @@ allprojects {
testImplementation group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

test {
useJUnitPlatform()
maxParallelForks = 1
}

configurations {
intTestImplementation.extendsFrom testImplementation
intTestRuntimeOnly.extendsFrom testRuntimeOnly
}
sourceSets {
intTest {
resources.srcDir file('src/intTest/resources')
scala {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file("${projectDir}/src/intTest/scala")
testing {
suites {
configureEach {
useJUnit()
targets.configureEach {
testTask.configure {
maxParallelForks = 1
}
}
}
intTest(JvmTestSuite) {
testType = TestSuiteType.INTEGRATION_TEST
// dependencies { ... } does not appear to work as advertised?
sources {
scala {
compileClasspath += sourceSets.test.compileClasspath + sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
targets.configureEach {
testTask.configure{
outputs.upToDateWhen { false }
mustRunAfter(test)
}
}
}
}
}


task intTest(type: Test) {
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath
outputs.upToDateWhen { false }

maxParallelForks = 1
}
check.dependsOn(intTest)
intTest.mustRunAfter(test)
check.dependsOn(testing.suites.intTest)

scoverage {
minimumRate = 0.5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'io.spring.dependency-management' version "1.0.4.RELEASE"
id 'org.scoverage'
id 'jvm-test-suite'
}

repositories {
Expand All @@ -27,39 +28,35 @@ dependencies {
testImplementation group: 'org.scalatest', name: "scalatest_${scalaVersionMajor}.${scalaVersionMinor}", version: scalatestVersion
}

test {
useJUnitPlatform()
}


configurations {
intTestImplementation.extendsFrom testImplementation
intTestRuntimeOnly.extendsFrom testRuntimeOnly
}
sourceSets {
intTest {
resources.srcDir file('src/intTest/resources')
scala {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file("${projectDir}/src/intTest/scala")
testing {
suites {
configureEach {
useJUnit()
targets.configureEach {
testTask.configure {
maxParallelForks = 1
}
}
}
intTest(JvmTestSuite) {
testType = TestSuiteType.INTEGRATION_TEST
// dependencies { ... } does not appear to work as advertised?
sources {
scala {
compileClasspath += sourceSets.test.compileClasspath + sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
targets.configureEach {
testTask.configure{
outputs.upToDateWhen { false }
mustRunAfter(test)
}
}
}
}
}

test {
maxParallelForks = 1
}

task intTest(type: Test) {
testClassesDirs = sourceSets.intTest.output.classesDirs
classpath = sourceSets.intTest.runtimeClasspath
outputs.upToDateWhen { false }

maxParallelForks = 1
}
check.dependsOn(intTest)
intTest.mustRunAfter(test)
check.dependsOn(testing.suites.intTest)

scoverage {
minimumRate = 0.6
Expand Down
Loading