Skip to content

Commit 860be24

Browse files
authored
Merge pull request #7 from cdsap/fix_configuration_cache_issue_on_build_scan_execution
Remove eager call on CommandLineWithOutputValue for BuildScan output
2 parents e1ed620 + e05881e commit 860be24

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ jobs:
2121
uses: gradle/gradle-build-action@v2
2222
- name: Execute Gradle build
2323
run: ./gradlew test
24+
env:
25+
GE_URL: ${{ secrets.GE_URL }}
26+
GE_API_KEY: ${{ secrets.GE_API_KEY }}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class InfoKotlinProcessPlugin : Plugin<Project> {
3131
project: Project,
3232
buildScanExtension: BuildScanExtension
3333
) {
34-
val processes = ConsolidateProcesses().consolidate(project.jStat().get(), project.jInfo().get())
34+
val jStat = project.jStat()
35+
val jInfo = project.jInfo()
3536

3637
buildScanExtension.buildFinished {
38+
val processes = ConsolidateProcesses().consolidate(jStat.get(), jInfo.get())
3739
BuildScanOutput(buildScanExtension, processes).addProcessesInfoToBuildScan()
3840
}
3941
}

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

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.cdsap.kotlinprocess
22

33
import junit.framework.TestCase.assertTrue
4+
import org.gradle.internal.impldep.org.junit.Assume.assumeTrue
45
import org.gradle.testkit.runner.GradleRunner
56
import org.junit.Rule
67
import org.junit.Test
@@ -40,7 +41,7 @@ class InfoKotlinProcessPluginTest {
4041
}
4142

4243
@Test
43-
fun testPluginIsCompatibleWithConfigurationCache() {
44+
fun testPluginIsCompatibleWithConfigurationCacheWithoutGradleEnterprise() {
4445
testProjectDir.newFile("build.gradle").appendText(
4546
"""
4647
plugins {
@@ -57,13 +58,68 @@ class InfoKotlinProcessPluginTest {
5758
listOf("7.5.1", "7.6").forEach {
5859
val firstBuild = GradleRunner.create()
5960
.withProjectDir(testProjectDir.root)
60-
.withArguments("compileKotlin", "--configuration-cache", "--configuration-cache-problems=warn")
61+
.withArguments("compileKotlin", "--configuration-cache")
6162
.withPluginClasspath()
6263
.withGradleVersion(it)
6364
.build()
6465
val secondBuild = GradleRunner.create()
6566
.withProjectDir(testProjectDir.root)
66-
.withArguments("compileKotlin", "--configuration-cache", "--configuration-cache-problems=warn")
67+
.withArguments("compileKotlin", "--configuration-cache")
68+
.withPluginClasspath()
69+
.withGradleVersion(it)
70+
.build()
71+
assertTrue(firstBuild.output.contains("Configuration cache entry stored"))
72+
assertTrue(secondBuild.output.contains("Configuration cache entry reused."))
73+
}
74+
}
75+
76+
77+
@Test
78+
fun testPluginIsCompatibleWithConfigurationCacheWithGradleEnterprise() {
79+
assumeTrue(
80+
"Gradle Enterprise URL and Access Key are set",
81+
System.getenv("GE_URL") != null && System.getenv("GE_API_KEY") != null
82+
)
83+
84+
testProjectDir.newFile("settings.gradle").appendText(
85+
"""
86+
plugins {
87+
id 'com.gradle.enterprise' version '3.12.2'
88+
}
89+
gradleEnterprise {
90+
server = "${System.getenv("GE_URL")}"
91+
accessKey="${System.getenv("GE_API_KEY")}"
92+
buildScan {
93+
capture { taskInputFiles = true }
94+
publishAlways()
95+
96+
}
97+
}
98+
""".trimIndent()
99+
)
100+
testProjectDir.newFile("build.gradle").appendText(
101+
"""
102+
plugins {
103+
id 'org.jetbrains.kotlin.jvm' version '1.7.21'
104+
id 'application'
105+
id 'io.github.cdsap.kotlinprocess'
106+
}
107+
repositories {
108+
mavenCentral()
109+
}
110+
111+
""".trimIndent()
112+
)
113+
listOf("7.5.1", "7.6").forEach {
114+
val firstBuild = GradleRunner.create()
115+
.withProjectDir(testProjectDir.root)
116+
.withArguments("compileKotlin", "--configuration-cache")
117+
.withPluginClasspath()
118+
.withGradleVersion(it)
119+
.build()
120+
val secondBuild = GradleRunner.create()
121+
.withProjectDir(testProjectDir.root)
122+
.withArguments("compileKotlin", "--configuration-cache")
67123
.withPluginClasspath()
68124
.withGradleVersion(it)
69125
.build()

0 commit comments

Comments
 (0)