Skip to content

Commit f5e3cc2

Browse files
authored
Merge pull request #88 from eyalroth/3.x
3.x
2 parents 08a7f50 + e5e0e90 commit f5e3cc2

File tree

93 files changed

+1990
-793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1990
-793
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
classes
22
build
3+
out
34
.gradle
45

56
*.iml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: groovy
22
script:
3-
- "./gradlew --info --stacktrace test"
3+
- "./gradlew --info --stacktrace check"

README.md

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,110 @@ gradle-scoverage
44
================
55
A plugin to enable the use of Scoverage in a gradle Scala project.
66

7-
Getting started
8-
---------------
9-
http://plugins.gradle.org/plugin/org.scoverage
7+
Usage
8+
-----
109

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
1211

13-
A further task `reportScoverage` produces XML and HTML reports for analysing test code coverage.
12+
### Available tasks
1413

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.
1615

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.
2217

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.
2521

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

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.
3425

35-
ReportScoverage
36-
---------------
26+
3. `checkScoverage`: Validates coverage according status according the generated reports (aggregated or not).
3727

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
3932

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:
4635

47-
Aggregating Reports
48-
-------------------
36+
You can configure the version of Scoverage that will be used. This plugin should
4937

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.
5140

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).
5445

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).
5647

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).
6049

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).
6251

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).
6454

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).
6658

67-
```groovy
68-
checkScoverage {
69-
reportDir = file("$buildDir/scoverage-aggregate")
70-
}
71-
```
59+
### Run without normal compilation
7260

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`).
7563

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`.
7768

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'
8280
}
8381
```
8482

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+
}
8689
87-
```
90+
// instead of this
8891
checkScoverage {
89-
coverageType = 'Line'
9092
minimumRate = 0.5
9193
}
9294
```
9395

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)
95100
checkScoverage {
96-
coverageType = 'Branch'
97-
minimumRate = 0.5
101+
reportDir = file("$buildDir/scoverage-aggregate")
98102
}
99103
```
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.

build.gradle

Lines changed: 79 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
// First, apply the publishing plugin
2-
buildscript {
3-
repositories {
4-
maven {
5-
url "https://plugins.gradle.org/m2/"
6-
}
7-
}
8-
dependencies {
9-
classpath "com.gradle.publish:plugin-publish-plugin:0.9.10"
10-
}
11-
}
12-
13-
apply plugin: "com.gradle.plugin-publish"
14-
description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage'
15-
if (project.version == 'unspecified') {
16-
version = '2.0.0-SNAPSHOT'
1+
plugins {
2+
id 'java-gradle-plugin'
3+
id "com.gradle.plugin-publish" version "0.10.0"
4+
id "org.jetbrains.gradle.plugin.idea-ext" version "0.4.2"
175
}
186

197
repositories {
20-
mavenCentral()
8+
jcenter()
219
}
2210

11+
group 'org.scoverage'
12+
description = 'gradle-scoverage is a Gradle plugin for calculating code coverage using Scoverage'
13+
version = '2.0.0-SNAPSHOT'
14+
2315
ext {
2416
website = 'http://scoverage.org'
2517
vcsUrl = 'https://github.com/scoverage/gradle-scoverage.git'
@@ -28,24 +20,61 @@ ext {
2820
sonatypePass = System.env.SONATYPE_PASS
2921
}
3022

31-
apply plugin: 'idea'
23+
gradlePlugin {
24+
plugins {
25+
gradleScoverage {
26+
id = 'org.scoverage'
27+
implementationClass = 'org.scoverage.ScoveragePlugin'
28+
}
29+
}
30+
}
31+
32+
pluginBundle {
33+
website = project.website
34+
vcsUrl = ext.vcsUrl
35+
description = project.description
36+
tags = ['coverage', 'scala', 'scoverage']
37+
plugins {
38+
scoveragePlugin {
39+
displayName = 'Gradle Scoverage plugin'
40+
}
41+
}
42+
}
43+
3244
apply plugin: 'maven'
3345
apply plugin: 'groovy'
3446

35-
group 'org.scoverage'
3647
sourceCompatibility = '1.6'
3748
targetCompatibility = '1.6'
3849

39-
configurations {
40-
scoverage
41-
compile.extendsFrom scoverage
50+
dependencies {
51+
compileOnly "org.scoverage:scalac-scoverage-plugin_2.12:1.3.1"
52+
compile group: 'commons-io', name: 'commons-io', version: '2.6'
53+
testCompile 'junit:junit:4.12'
54+
testCompile 'org.hamcrest:hamcrest-library:1.3'
55+
}
56+
57+
sourceSets {
58+
functionalTest {
59+
java.srcDir file('src/functionalTest/java')
60+
resources.srcDir file('src/functionalTest/resources')
61+
compileClasspath += sourceSets.main.output + configurations.testRuntime
62+
runtimeClasspath += output + compileClasspath
63+
}
4264
}
4365

44-
dependencies {
45-
compile gradleApi()
46-
compile localGroovy()
47-
scoverage "org.scoverage:scalac-scoverage-plugin_2.11:1.1.1"
48-
testCompile 'junit:junit:4.12', 'org.hamcrest:hamcrest-library:1.3'
66+
task functionalTest(type: Test) {
67+
description = 'Runs the functional tests.'
68+
group = 'verification'
69+
testClassesDirs = sourceSets.functionalTest.output.classesDirs
70+
classpath = sourceSets.functionalTest.runtimeClasspath
71+
mustRunAfter test
72+
}
73+
74+
check.dependsOn functionalTest
75+
76+
gradlePlugin {
77+
testSourceSets sourceSets.functionalTest
4978
}
5079

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

61-
test {
62-
dependsOn jar
63-
}
64-
6590
artifacts {
6691
archives jar
6792
archives groovydocJar
@@ -75,25 +100,11 @@ if (project.properties.containsKey('signing.keyId')) {
75100
}
76101
}
77102

78-
pluginBundle {
79-
website = project.website
80-
vcsUrl = project.vcsUrl
81-
description = project.description
82-
tags = ['coverage', 'scala', 'scoverage']
83-
withDependencies { it.clear() }
84-
plugins {
85-
scoveragePlugin {
86-
id = 'org.scoverage'
87-
displayName = 'Gradle Scoverage plugin'
88-
}
89-
}
90-
}
91-
92103
uploadArchives {
93104
repositories {
94105
mavenDeployer {
95106
if (project.properties.containsKey('signing.keyId')) {
96-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
107+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
97108
}
98109

99110
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
@@ -132,8 +143,30 @@ uploadArchives {
132143
developer {
133144
id 'D-Roch'
134145
}
146+
developer {
147+
id 'eyalroth'
148+
}
135149
}
136150
}
137151
}
138152
}
139153
}
154+
155+
// see https://stackoverflow.com/questions/44679007
156+
task fixIdeaPluginClasspath {
157+
doFirst {
158+
configure(tasks.pluginUnderTestMetadata) {
159+
def ideaClassesPath = project.buildDir.toPath().resolveSibling("out").resolve("production")
160+
def newClasspath = pluginClasspath as List
161+
newClasspath.add(0, ideaClassesPath)
162+
pluginClasspath.setFrom(newClasspath)
163+
}
164+
}
165+
}
166+
pluginUnderTestMetadata.mustRunAfter(fixIdeaPluginClasspath)
167+
168+
idea.project.settings {
169+
taskTriggers {
170+
beforeBuild fixIdeaPluginClasspath, pluginUnderTestMetadata
171+
}
172+
}

init-scoverage.gradle

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)