Skip to content
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

Designed and implemented Kover API version 2 #190

Merged
merged 10 commits into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
541 changes: 295 additions & 246 deletions README.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build.gradle.kts
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.6.10"
kotlin("jvm") version "1.7.10"

`java-gradle-plugin`
`maven-publish`
Expand All @@ -24,16 +24,16 @@ dependencies {
// exclude transitive dependency on stdlib, the Gradle version should be used
compileOnly(kotlin("stdlib"))

compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${property("kotlin.version")}")
compileOnly("com.android.tools.build:gradle:4.2.2")

testImplementation(kotlin("test"))

"functionalTestImplementation"(gradleTestKit())
// dependencies only for plugin's classpath to work with Kotlin Multi-Platform and Android plugins
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.10")
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-compiler-runner:1.6.10")
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-gradle-plugin:${property("kotlin.version")}")
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-compiler-embeddable:${property("kotlin.version")}")
"functionalTestCompileOnly"("org.jetbrains.kotlin:kotlin-compiler-runner:${property("kotlin.version")}")
}

java {
Expand Down Expand Up @@ -73,7 +73,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
// Kover works with the stdlib of at least version `1.4.x`
languageVersion = "1.4"
apiVersion = "1.4"
// Kotlin compiler 1.6 issues a warning if `languageVersion` or `apiVersion` 1.4 is used - suppress it
// Kotlin compiler 1.7 issues a warning if `languageVersion` or `apiVersion` 1.4 is used - suppress it
freeCompilerArgs = freeCompilerArgs + "-Xsuppress-version-warnings"
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/PublicationMavenCentral.kt
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import org.gradle.api.*
Expand Down
323 changes: 323 additions & 0 deletions docs/migration-to-0.6.0.md
@@ -0,0 +1,323 @@
# Main differences

The new API allows you to configure Kover in a more flexible manner, while being more concise than the previous API.
From now on, there is no need to configure each Kover task separately.

In the new API, in order to respect upcoming Gradle conventions, the plugin should be explicitly applied to
each project that needs coverage.
To create merged tasks (that collect test coverage from different projects), enable it by `koverMerged.enable()` or
```
koverMerged {
enable()
}
```
in one project, which will be a merged report container.

To configure reports that collect coverage only for tests from one project, the `kover { }` project extension is used.
To configure merged reports, the `koverMerged { }` project extension is used.

# Migration Issues

## Root kover extension

### type of `isDisabled` property changed from `Boolean` to `Property<Boolean>`.

for Kotlin script: change `isDisabled = true` to `isDisabled.set(true)`

### Properties `coverageEngine`, `intellijEngineVersion` and `jacocoEngineVersion` were removed.

Use property `engine` - it combines version and coverage engine vendor.

To use IntelliJ Coverage Engine with default version write `engine.set(kotlinx.kover.api.DefaultIntellijEngine)`
(Kotlin) or `engine = kotlinx.kover.api.DefaultIntellijEngine.INSTANCE` (Groovy).

To use IntelliJ Coverage Engine with custom version write `engine.set(kotlinx.kover.api.IntellijEngine("version"))`
(Kotlin) or `engine = kotlinx.kover.api.IntellijEngine("version")` (Groovy).

To use JaCoCo Coverage Engine with default version write `engine.set(kotlinx.kover.api.DefaultJacocoEngine)`
(Kotlin) or `engine = kotlinx.kover.api.DefaultJacocoEngine.INSTANCE` (Groovy).

To use JaCoCo Coverage Engine with custom version write `engine.set(kotlinx.kover.api.JacocoEngine("version"))`
(Kotlin) or `engine = kotlinx.kover.api.JacocoEngine("version")` (Groovy).

### Property "generateReportOnCheck" was removed

Use the properties individually for each report

```
kover {
xmlReport {
onCheck.set(true)
}

htmlReport {
onCheck.set(true)
}

verify {
onCheck.set(true)
}
}
```

### property `disabledProjects` was removed

Use inclusion list in project filters

```
koverMerged {
enable()
filters {
projects {
includes.add(":path or unique project name")
}
}
}
```

If `includes` are empty, all subprojects and current project are used in merged reports.

### Property `instrumentAndroidPackage` was removed

There is no replacement. At the moment, all classes from the packages "android." and "com.android.*" excluded from
instrumentation.

### property `runAllTestsForProjectTask` was removed

TBD

## Kover extension for test task

### type of `isDisabled` property changed from "Boolean" to `Property<Boolean>`".

Solution for Kotlin script: change `isDisabled = true` to `isDisabled.set(true)`

### `binaryReportFile` was renamed to `reportFile`

Solution: change `binaryReportFile` to `reportFile`

### Type of `includes` property changed from `List<String>` to `ListProperty<String>`

Solution for Kotlin: change `includes = listOf("com.example.*", "foo.bar.*")`
to `includes.addAll("com.example.*", "foo.bar.*")`

Solution for Groovy: change `includes = ["com.example.*", "foo.bar.*"]`
to `includes.addAll("com.example.*", "foo.bar.*")`

### type of `excludes` property changed from `List<String>` to `ListProperty<String>`

Solution for Kotlin: change `excludes = listOf("com.example.*", "foo.bar.*")`
to `includes.addAll("com.example.*", "foo.bar.*")`

Solution for Groovy: change `excludes = ["com.example.*", "foo.bar.*"]`
to `includes.addAll("com.example.*", "foo.bar.*")`

## `koverXmlReport` and `koverMergedXmlReport` tasks configuration

### Property `xmlReportFile` was removed
Solution: use property in Kover extension at the root of the project

```
kover {
xmlReport {
reportFile.set(yourFile)
}
}
```
&ast; for `xmlReportFile` task use `koverMerged { ... }` extension of the project.

### Property `includes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
&ast; for `xmlReportFile` task use `koverMerged { ... }` extension of the project.

### Property `excludes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
&ast; for `xmlReportFile` task use `koverMerged { ... }` extension of the project.

## `koverHtmlReport` and `koverMergedHtmlReport` tasks configuration

### Property `htmlReportDir` was removed

Solution: use property in Kover extension at the root of the project

```
kover {
htmlReport {
reportDir.set(yourDir)
}
}
```
&ast; for `koverMergedHtmlReport` task use `koverMerged { ... }` extension of the project.

### Property `includes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
&ast; for `koverMergedHtmlReport` task use `koverMerged { ... }` extension of the project.

### Property `excludes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
&ast; for `koverMergedHtmlReport` task use `koverMerged { ... }` extension of the project.

## `koverVerify` and `koverMergedVerify` tasks configuration

### Function `rule` was removed

Solution: use function in Kover extension at the root of the project

```
kover {
verify {
rule {
// your verification rule
}
}
}
```

* For `koverMergedVerify` task use `koverMerged { ... }` extension of the project.

### Property `includes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
&ast; for `koverMergedVerify` task use `koverMerged { ... }` extension of the project.

### Property `excludes` was removed

Solution for Kotlin: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
```

Solution for Groovy: use filter in Kover extension at the root of the project

```
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
```
* For `koverMergedVerify` task use `koverMerged { ... }` extension of the project.

3 changes: 2 additions & 1 deletion gradle.properties
@@ -1,4 +1,5 @@
version=0.5.1
version=0.6.0-SNAPSHOT
group=org.jetbrains.kotlinx

kotlin.version=1.7.10
kotlin.code.style=official
Expand Up @@ -14,15 +14,15 @@ internal class AdaptersTests : BaseGradleScriptTest() {
Classes from plugins applied in subproject not accessible for Kover in root project.
Therefore, Kover is forced to use reflection to work with extensions of the kotlin multiplatform plugin.
*/
internalSample("different-plugins")
sampleBuild("different-plugins")
.run("koverMergedXmlReport") {
xml(defaultMergedXmlReport()) {
classCounter("org.jetbrains.CommonClass").assertFullyCovered()
classCounter("org.jetbrains.JvmClass").assertFullyCovered()
}
}

internalSample("different-plugins")
sampleBuild("different-plugins")
.run("koverXmlReport") {
subproject("subproject-multiplatform") {
xml(defaultXmlReport()) {
Expand Down