@@ -4,96 +4,110 @@ gradle-scoverage
4
4
================
5
5
A plugin to enable the use of Scoverage in a gradle Scala project.
6
6
7
- Getting started
8
- ---------------
9
- http://plugins.gradle.org/plugin/org.scoverage
7
+ Usage
8
+ -----
10
9
11
- This creates an additional task ` testScoverage ` which will run tests against instrumented code.
10
+ You can find instructions on how to apply the plugin at: http://plugins.gradle.org/plugin/org.scoverage
12
11
13
- A further task ` reportScoverage ` produces XML and HTML reports for analysing test code coverage.
12
+ ### Available tasks
14
13
15
- You need to configure the version of Scoverage that will be used. This plugin should be compatible with all 1+ versions .
14
+ 1 . ` reportScoverage ` : Produces XML and HTML reports for analysing test code coverage .
16
15
17
- ``` groovy
18
- dependencies {
19
- scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.1.0', 'org.scoverage:scalac-scoverage-runtime_2.11:1.1.0'
20
- }
21
- ```
16
+ 2 . ` aggregateScoverage ` : An experimental support for aggregating coverage statistics in composite builds.
22
17
23
- Then launch command :
24
- ` gradle reportScoverage ` or ` gradle checkScoverage `
18
+ When applied on a project with sub-projects, the plugin will create the aggregation task ` aggregateScoverage ` , which
19
+ will first generate reports for each project individually (including the parent project), and will then generate an
20
+ aggregated result based on these reports.
25
21
26
- Available tasks
27
- ---------------
22
+ The aggregated report will override the parent-project specific report (` parent-project/build/reports/scoverage ` ).
28
23
29
- * testScoverage - Executes all tests and creates Scoverage XML report with information about code coverage
30
- * reportScoverage - Generates reports (see below).
31
- * aggregateScoverage - Aggregates reports from multiple sub-projects (see below).
32
- * checkScoverage - See below.
33
- * compileScoverageScala - Instruments code without running tests.
24
+ One can still use ` reportScoverage ` in order to generate a report without aggregation.
34
25
35
- ReportScoverage
36
- ---------------
26
+ 3 . ` checkScoverage ` : Validates coverage according status according the generated reports (aggregated or not).
37
27
38
- You can configure output generated by ` gradle reportScoverage ` using flags:
28
+ ` gradle checkScoverage ` will automatically invoke ` reportScoverage ` but it won't generate aggregated reports.
29
+ In order to check coverage of aggregated reports one should use ` gradle checkScoverage aggregateScoverage ` .
30
+
31
+ ### Configuration
39
32
40
- | Flag name | Default value | Description |
41
- | ------------------------| ---------------| -------------------------------------------------|
42
- | coverageOutputCobertura | true | Enables/disables cobertura.xml file generation. |
43
- | coverageOutputXML | true | Enables/disables scoverage XML output. |
44
- | coverageOutputHTML | true | Enables/disables scoverage HTML output. |
45
- | coverageDebug | false | Enables/disables scoverage debug output. |
33
+ The plugin exposes multiple options that can be configured by setting them in an ` scoverage ` block within the project's
34
+ build script. These options are as follows:
46
35
47
- Aggregating Reports
48
- -------------------
36
+ You can configure the version of Scoverage that will be used. This plugin should
49
37
50
- There is now experimental support for aggregating coverage statistics across sub-projects.
38
+ * ` scoverageVersion = <String> ` (default ` "1.3.1" ` ): The version of the scoverage scalac plugin. This (gradle) plugin
39
+ should be compatible with all 1+ versions.
51
40
52
- The project hosting the aggregation task ** must** be configured as the sub-projects are;
53
- i.e. with the scoverage plugin applied and the scoverage dependencies configured.
41
+ * ` scoverageScalaVersion = <String> ` (default ` "2.12" ` ): The scala version of the scoverage scalac plugin. This will
42
+ be overridden by the version of the ` scala-library ` compile dependency (if the dependency is configured).
43
+
44
+ * ` coverageOutputCobertura = <boolean> ` (default ` true ` ): Enables/disables cobertura.xml file generation (for both aggregated and non-aggregated reports).
54
45
55
- You also have to declare this task:
46
+ * ` coverageOutputXML = <boolean> ` (default ` true ` ): Enables/disables scoverage XML output (for both aggregated and non-aggregated reports).
56
47
57
- ``` groovy
58
- task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
59
- ```
48
+ * ` coverageOutputHTML = <boolean> ` (default ` true ` ): Enables/disables scoverage HTML output (for both aggregated and non-aggregated reports).
60
49
61
- This will produce a report into ` build/ scoverage-aggregate ` directory .
50
+ * ` coverageDebug = <boolean> ` (default ` false ` ): Enables/disables scoverage debug output (for both aggregated and non-aggregated reports) .
62
51
63
- Aggregation uses same flags as reporting for enabling/disabling different output types.
52
+ * ` minimumRate = <double> ` (default ` 0.75 ` ): The minimum amount of coverage in decimal proportion (` 1.0 ` == 100%)
53
+ required for the validation to pass (otherwise ` checkScoverage ` will fail the build).
64
54
65
- For checking coverage of the aggregated result, configure the checkScoverage task:
55
+ * ` coverageType = <"Statement" | "Branch" | "Line"> ` (default ` "Statement" ` ): The type of coverage validated by the
56
+ ` checkScoverage ` task. For more information on the different types, please refer to the documentation of the scalac
57
+ plugin (https://github.com/scoverage/scalac-scoverage-plugin ).
66
58
67
- ``` groovy
68
- checkScoverage {
69
- reportDir = file("$buildDir/scoverage-aggregate")
70
- }
71
- ```
59
+ ### Run without normal compilation
72
60
73
- CheckScoverage
74
- --------------
61
+ By default, running any of the plugin tasks will compile the code both using "normal" compilation ( ` compileScala ` )
62
+ and using the scoverage scalac plugin ( ` compileScoverageScala ` ).
75
63
76
- By default, when you launch ` gradle checkScoverage ` build fail if only 75% of statements in project is covered by tests.
64
+ In cases where you only wish to generate reports / validate coverage, but are not interested in publishing the code,
65
+ it is possible to only compile the code with the scoverage scalac plugin, thus reducing build times significantly.
66
+ In order to do so, simply add the arguments ` -x compileScala ` to the gradle execution.
67
+ For example: ` gradle reportScoverage -x compileScala ` .
77
68
78
- To configure it as you want, add this configuration :
79
- ```
80
- checkScoverage {
81
- minimumRate = 0.5
69
+ Migration to 3.x
70
+ ----------------
71
+
72
+ * No more ` testScoverage ` task; instead, ` test ` will run coverage whenever the build is invoked with any of the scoverage tasks.
73
+
74
+ * No more need to declare scalac dependencies:
75
+ ``` groovy
76
+ // can safely delete this from build scripts
77
+ dependencies {
78
+ scoverage group: 'org.scoverage', name: 'scalac-scoverage-plugin_2.12', version: '1.3.1'
79
+ scoverage group: 'org.scoverage', name: 'scalac-scoverage-runtime_2.12', version: '1.3.1'
82
80
}
83
81
```
84
82
85
- You can also modify type of value to check from ` Statement ` s to ` Line ` s or ` Branch ` es:
83
+ * All configurations are configured in ` scoverage ` block. For instance:
84
+ ``` groovy
85
+ // do this
86
+ scoverage {
87
+ minimumRate = 0.5
88
+ }
86
89
87
- ```
90
+ // instead of this
88
91
checkScoverage {
89
- coverageType = 'Line'
90
92
minimumRate = 0.5
91
93
}
92
94
```
93
95
94
- ```
96
+ * No more need to declare aggregation task:
97
+ ``` groovy
98
+ // can safely delete this from build scripts
99
+ task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
95
100
checkScoverage {
96
- coverageType = 'Branch'
97
- minimumRate = 0.5
101
+ reportDir = file("$buildDir/scoverage-aggregate")
98
102
}
99
103
```
104
+
105
+ Release history
106
+ ---------------
107
+
108
+ ##### (not released yet) - 3.0.0
109
+
110
+ * Auto resolution of scalac plugin dependencies.
111
+ * Aggregation task declared by default.
112
+ * Deletion of non-instrumented classes, allowing for better integration with other coverage tools such as cobertura.
113
+ * Ability to execute coverage without "normal" compilation, thus reducing build times.
0 commit comments