Skip to content

Commit 8b622ed

Browse files
authored
Reporting when hit configuration cache (#40)
* fix reporting_when_hit_configuration_cache * correct versions to test
1 parent 0698e18 commit 8b622ed

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Apply the plugin in the main `build.gradle(.kts)` configuration file:
99
Using the plugins DSL:
1010
``` groovy
1111
plugins {
12-
id("io.github.cdsap.kotlinprocess") version "0.1.6"
12+
id("io.github.cdsap.kotlinprocess") version "0.1.7"
1313
}
1414
```
1515

@@ -20,7 +20,7 @@ buildscript {
2020
gradlePluginPortal()
2121
}
2222
dependencies {
23-
classpath("io.github.cdsap:infokotlinprocess:0.1.6")
23+
classpath("io.github.cdsap:infokotlinprocess:0.1.7")
2424
}
2525
}
2626
@@ -31,7 +31,7 @@ apply(plugin = "io.github.cdsap.kotlinprocess")
3131
Using the plugins DSL:
3232
``` groovy
3333
plugins {
34-
id "io.github.cdsap.kotlinprocess" version "0.1.6"
34+
id "io.github.cdsap.kotlinprocess" version "0.1.7"
3535
}
3636
3737
```
@@ -43,7 +43,7 @@ buildscript {
4343
gradlePluginPortal()
4444
}
4545
dependencies {
46-
classpath "io.github.cdsap:infokotlinprocess:0.1.6"
46+
classpath "io.github.cdsap:infokotlinprocess:0.1.7"
4747
}
4848
}
4949
@@ -56,7 +56,7 @@ Build Scan:
5656

5757
![](images/buildscan.png)
5858

59-
The field `Usage` represents the value obtained at the end of the build using `jstat` on the JVM process.
59+
The field `Usage` represents the value obtained at the end of the build using `jstat` on the JVM process.
6060

6161
### Build Output
6262
If you are not using Gradle Enterprise, the information about the Kotlin processes will be included at the end of the build:

src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessBuildService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import io.github.cdsap.kotlinprocess.output.ConsoleOutput
66
import org.gradle.api.provider.Provider
77
import org.gradle.api.services.BuildService
88
import org.gradle.api.services.BuildServiceParameters
9+
import org.gradle.tooling.events.FinishEvent
10+
import org.gradle.tooling.events.OperationCompletionListener
911

1012
abstract class InfoKotlinProcessBuildService :
11-
BuildService<InfoKotlinProcessBuildService.Params>, AutoCloseable {
13+
BuildService<InfoKotlinProcessBuildService.Params>, AutoCloseable,
14+
OperationCompletionListener {
1215
interface Params : BuildServiceParameters {
1316
var jInfoProvider: Provider<String>
1417
var jStatProvider: Provider<String>
@@ -25,4 +28,6 @@ abstract class InfoKotlinProcessBuildService :
2528
ConsoleOutput(processes).print()
2629
}
2730
}
31+
32+
override fun onFinish(event: FinishEvent?) {}
2833
}

src/main/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPlugin.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import io.github.cdsap.valuesourceprocess.jStat
1212
import org.gradle.api.Plugin
1313
import org.gradle.api.Project
1414
import org.gradle.api.provider.Provider
15+
import org.gradle.build.event.BuildEventsListenerRegistry
16+
import org.gradle.kotlin.dsl.support.serviceOf
1517

1618

1719
class InfoKotlinProcessPlugin : Plugin<Project> {
@@ -33,12 +35,13 @@ class InfoKotlinProcessPlugin : Plugin<Project> {
3335
}
3436

3537
private fun consoleReporting(project: Project) {
36-
project.gradle.sharedServices.registerIfAbsent(
38+
val service = project.gradle.sharedServices.registerIfAbsent(
3739
"kotlinProcessService", InfoKotlinProcessBuildService::class.java
3840
) {
3941
parameters.jInfoProvider = project.jInfo(nameProcess)
4042
parameters.jStatProvider = project.jStat(nameProcess)
41-
}.get()
43+
}
44+
project.serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
4245
}
4346

4447
private fun buildScanEnterpriseReporting(

src/test/kotlin/io/github/cdsap/kotlinprocess/InfoKotlinProcessPluginTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.junit.rules.TemporaryFolder
1010

1111
class InfoKotlinProcessPluginTest {
1212

13-
private val gradleVersions = listOf("7.6.2", "8.1.1", "8.6", "8.7")
13+
private val gradleVersions = listOf("8.6", "8.7", "8.12.1")
1414

1515
@Rule
1616
@JvmField
@@ -35,19 +35,21 @@ class InfoKotlinProcessPluginTest {
3535
gradleVersions.forEach {
3636
val firstBuild = GradleRunner.create()
3737
.withProjectDir(testProjectDir.root)
38-
.withArguments("compileKotlin", "--configuration-cache")
38+
.withArguments("clean", "compileKotlin", "--no-build-cache", "--configuration-cache")
3939
.withPluginClasspath()
4040
.withGradleVersion(it)
4141
.build()
4242
val secondBuild = GradleRunner.create()
4343
.withProjectDir(testProjectDir.root)
44-
.withArguments("compileKotlin", "--configuration-cache")
44+
.withArguments("clean", "compileKotlin", "--no-build-cache", "--configuration-cache")
4545
.withPluginClasspath()
4646
.withGradleVersion(it)
4747
.build()
48-
4948
assertTrue(firstBuild.output.contains("Configuration cache entry stored"))
49+
assertTrue(firstBuild.output.contains("Kotlin processes"))
5050
assertTrue(secondBuild.output.contains("Configuration cache entry reused."))
51+
assertTrue(secondBuild.output.contains("Kotlin processes"))
52+
5153
}
5254
}
5355

0 commit comments

Comments
 (0)