Skip to content

3.x #88

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 17 commits into from
Feb 24, 2019
Merged

3.x #88

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
9c2c096
Update the project according to the current (gradle 5.0) plugin devel…
eyalroth Jan 29, 2019
de988f1
Add new functional tests
eyalroth Jan 29, 2019
78dc56f
Make the plugin configure the scalac-plugin classpath and the aggrega…
eyalroth Jan 29, 2019
b2fbb84
Properly handle report, check and aggregation tasks in multi-module p…
eyalroth Jan 29, 2019
22be0bd
Move the coverage XML validation to the functional tests and remove t…
eyalroth Jan 30, 2019
e11b331
Remove the "testScoverage" task and make "test" run the coverage (by …
eyalroth Jan 30, 2019
0a6ec0b
Make the plugin delete non-instrumented classes from the output direc…
eyalroth Jan 31, 2019
ad39e96
Allow running scoverage without running the normal compilation (only …
eyalroth Jan 31, 2019
7e17f53
Make the check-task flags configurable via the extension and not via …
eyalroth Jan 31, 2019
096d286
Update README.md with all of the latest changes
eyalroth Jan 31, 2019
1044b8a
Move all system prints to logger
eyalroth Feb 1, 2019
67e5106
Fix checking without aggregation on multi-module with no source code …
eyalroth Feb 1, 2019
269b17c
Add a functional test for a multi-module project with multiple scala …
eyalroth Feb 1, 2019
213239b
Add a functional test for a multi-module project mixed with both scal…
eyalroth Feb 1, 2019
57e6d27
Add compatibility with spring's dependency management plugin
eyalroth Feb 1, 2019
ea988ae
Change the usage of running without normal compilation and fix it in …
eyalroth Feb 3, 2019
e5e0e90
Update README.md with release history and instructions on how to migr…
eyalroth Feb 3, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
classes
build
out
.gradle

*.iml
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: groovy
script:
- "./gradlew --info --stacktrace test"
- "./gradlew --info --stacktrace check"
132 changes: 73 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,110 @@ gradle-scoverage
================
A plugin to enable the use of Scoverage in a gradle Scala project.

Getting started
---------------
http://plugins.gradle.org/plugin/org.scoverage
Usage
-----

This creates an additional task `testScoverage` which will run tests against instrumented code.
You can find instructions on how to apply the plugin at: http://plugins.gradle.org/plugin/org.scoverage

A further task `reportScoverage` produces XML and HTML reports for analysing test code coverage.
### Available tasks

You need to configure the version of Scoverage that will be used. This plugin should be compatible with all 1+ versions.
1. `reportScoverage`: Produces XML and HTML reports for analysing test code coverage.

```groovy
dependencies {
scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.1.0', 'org.scoverage:scalac-scoverage-runtime_2.11:1.1.0'
}
```
2. `aggregateScoverage`: An experimental support for aggregating coverage statistics in composite builds.

Then launch command :
`gradle reportScoverage` or `gradle checkScoverage`
When applied on a project with sub-projects, the plugin will create the aggregation task `aggregateScoverage`, which
will first generate reports for each project individually (including the parent project), and will then generate an
aggregated result based on these reports.

Available tasks
---------------
The aggregated report will override the parent-project specific report (`parent-project/build/reports/scoverage`).

* testScoverage - Executes all tests and creates Scoverage XML report with information about code coverage
* reportScoverage - Generates reports (see below).
* aggregateScoverage - Aggregates reports from multiple sub-projects (see below).
* checkScoverage - See below.
* compileScoverageScala - Instruments code without running tests.
One can still use `reportScoverage` in order to generate a report without aggregation.

ReportScoverage
---------------
3. `checkScoverage`: Validates coverage according status according the generated reports (aggregated or not).

You can configure output generated by `gradle reportScoverage` using flags:
`gradle checkScoverage` will automatically invoke `reportScoverage` but it won't generate aggregated reports.
In order to check coverage of aggregated reports one should use `gradle checkScoverage aggregateScoverage`.

### Configuration

| Flag name | Default value | Description |
| ------------------------|---------------|-------------------------------------------------|
| coverageOutputCobertura | true | Enables/disables cobertura.xml file generation. |
| coverageOutputXML | true | Enables/disables scoverage XML output. |
| coverageOutputHTML | true | Enables/disables scoverage HTML output. |
| coverageDebug | false | Enables/disables scoverage debug output. |
The plugin exposes multiple options that can be configured by setting them in an `scoverage` block within the project's
build script. These options are as follows:

Aggregating Reports
-------------------
You can configure the version of Scoverage that will be used. This plugin should

There is now experimental support for aggregating coverage statistics across sub-projects.
* `scoverageVersion = <String>` (default `"1.3.1"`): The version of the scoverage scalac plugin. This (gradle) plugin
should be compatible with all 1+ versions.

The project hosting the aggregation task **must** be configured as the sub-projects are;
i.e. with the scoverage plugin applied and the scoverage dependencies configured.
* `scoverageScalaVersion = <String>` (default `"2.12"`): The scala version of the scoverage scalac plugin. This will
be overridden by the version of the `scala-library` compile dependency (if the dependency is configured).

* `coverageOutputCobertura = <boolean>` (default `true`): Enables/disables cobertura.xml file generation (for both aggregated and non-aggregated reports).

You also have to declare this task:
* `coverageOutputXML = <boolean>` (default `true`): Enables/disables scoverage XML output (for both aggregated and non-aggregated reports).

```groovy
task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
```
* `coverageOutputHTML = <boolean>` (default `true`): Enables/disables scoverage HTML output (for both aggregated and non-aggregated reports).

This will produce a report into `build/scoverage-aggregate` directory.
* `coverageDebug = <boolean>` (default `false`): Enables/disables scoverage debug output (for both aggregated and non-aggregated reports).

Aggregation uses same flags as reporting for enabling/disabling different output types.
* `minimumRate = <double>` (default `0.75`): The minimum amount of coverage in decimal proportion (`1.0` == 100%)
required for the validation to pass (otherwise `checkScoverage` will fail the build).

For checking coverage of the aggregated result, configure the checkScoverage task:
* `coverageType = <"Statement" | "Branch" | "Line">` (default `"Statement"`): The type of coverage validated by the
`checkScoverage` task. For more information on the different types, please refer to the documentation of the scalac
plugin (https://github.com/scoverage/scalac-scoverage-plugin).

```groovy
checkScoverage {
reportDir = file("$buildDir/scoverage-aggregate")
}
```
### Run without normal compilation

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

By default, when you launch `gradle checkScoverage` build fail if only 75% of statements in project is covered by tests.
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 `-x compileScala` to the gradle execution.
For example: `gradle reportScoverage -x compileScala`.

To configure it as you want, add this configuration :
```
checkScoverage {
minimumRate = 0.5
Migration to 3.x
----------------

* No more `testScoverage` task; instead, `test` will run coverage whenever the build is invoked with any of the scoverage tasks.

* No more need to declare scalac dependencies:
```groovy
// can safely delete this from build scripts
dependencies {
scoverage group: 'org.scoverage', name: 'scalac-scoverage-plugin_2.12', version: '1.3.1'
scoverage group: 'org.scoverage', name: 'scalac-scoverage-runtime_2.12', version: '1.3.1'
}
```

You can also modify type of value to check from `Statement`s to `Line`s or `Branch`es:
* All configurations are configured in `scoverage` block. For instance:
```groovy
// do this
scoverage {
minimumRate = 0.5
}

```
// instead of this
checkScoverage {
coverageType = 'Line'
minimumRate = 0.5
}
```

```
* No more need to declare aggregation task:
```groovy
// can safely delete this from build scripts
task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
checkScoverage {
coverageType = 'Branch'
minimumRate = 0.5
reportDir = file("$buildDir/scoverage-aggregate")
}
```

Release history
---------------

##### (not released yet) - 3.0.0

* Auto resolution of scalac plugin dependencies.
* Aggregation task declared by default.
* Deletion of non-instrumented classes, allowing for better integration with other coverage tools such as cobertura.
* Ability to execute coverage without "normal" compilation, thus reducing build times.
125 changes: 79 additions & 46 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
// First, apply the publishing plugin
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.10"
}
}

apply plugin: "com.gradle.plugin-publish"
description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage'
if (project.version == 'unspecified') {
version = '2.0.0-SNAPSHOT'
plugins {
id 'java-gradle-plugin'
id "com.gradle.plugin-publish" version "0.10.0"
id "org.jetbrains.gradle.plugin.idea-ext" version "0.4.2"
}

repositories {
mavenCentral()
jcenter()
}

group 'org.scoverage'
description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage'
version = '2.0.0-SNAPSHOT'

ext {
website = 'http://scoverage.org'
vcsUrl = 'https://github.com/scoverage/gradle-scoverage.git'
Expand All @@ -28,24 +20,61 @@ ext {
sonatypePass = System.env.SONATYPE_PASS
}

apply plugin: 'idea'
gradlePlugin {
plugins {
gradleScoverage {
id = 'org.scoverage'
implementationClass = 'org.scoverage.ScoveragePlugin'
}
}
}

pluginBundle {
website = project.website
vcsUrl = ext.vcsUrl
description = project.description
tags = ['coverage', 'scala', 'scoverage']
plugins {
scoveragePlugin {
displayName = 'Gradle Scoverage plugin'
}
}
}

apply plugin: 'maven'
apply plugin: 'groovy'

group 'org.scoverage'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'

configurations {
scoverage
compile.extendsFrom scoverage
dependencies {
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.3.1"
compile group: 'commons-io', name: 'commons-io', version: '2.6'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
}

sourceSets {
functionalTest {
java.srcDir file('src/functionalTest/java')
resources.srcDir file('src/functionalTest/resources')
compileClasspath += sourceSets.main.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}

dependencies {
compile gradleApi()
compile localGroovy()
scoverage "org.scoverage:scalac-scoverage-plugin_2.11:1.1.1"
testCompile 'junit:junit:4.12', 'org.hamcrest:hamcrest-library:1.3'
task functionalTest(type: Test) {
description = 'Runs the functional tests.'
group = 'verification'
testClassesDirs = sourceSets.functionalTest.output.classesDirs
classpath = sourceSets.functionalTest.runtimeClasspath
mustRunAfter test
}

check.dependsOn functionalTest

gradlePlugin {
testSourceSets sourceSets.functionalTest
}

task groovydocJar(type: Jar, dependsOn: groovydoc) {
Expand All @@ -58,10 +87,6 @@ task sourcesJar(type: Jar) {
classifier = 'sources'
}

test {
dependsOn jar
}

artifacts {
archives jar
archives groovydocJar
Expand All @@ -75,25 +100,11 @@ if (project.properties.containsKey('signing.keyId')) {
}
}

pluginBundle {
website = project.website
vcsUrl = project.vcsUrl
description = project.description
tags = ['coverage', 'scala', 'scoverage']
withDependencies { it.clear() }
plugins {
scoveragePlugin {
id = 'org.scoverage'
displayName = 'Gradle Scoverage plugin'
}
}
}

uploadArchives {
repositories {
mavenDeployer {
if (project.properties.containsKey('signing.keyId')) {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
}

snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
Expand Down Expand Up @@ -132,8 +143,30 @@ uploadArchives {
developer {
id 'D-Roch'
}
developer {
id 'eyalroth'
}
}
}
}
}
}

// see https://stackoverflow.com/questions/44679007
task fixIdeaPluginClasspath {
doFirst {
configure(tasks.pluginUnderTestMetadata) {
def ideaClassesPath = project.buildDir.toPath().resolveSibling("out").resolve("production")
def newClasspath = pluginClasspath as List
newClasspath.add(0, ideaClassesPath)
pluginClasspath.setFrom(newClasspath)
}
}
}
pluginUnderTestMetadata.mustRunAfter(fixIdeaPluginClasspath)

idea.project.settings {
taskTriggers {
beforeBuild fixIdeaPluginClasspath, pluginUnderTestMetadata
}
}
7 changes: 0 additions & 7 deletions init-scoverage.gradle

This file was deleted.

Loading