Skip to content

Commit bbae50b

Browse files
Fix configuration cache compatibility issues
- Add endpoint property to UploadArtifactTask to eliminate project references during execution - Replace non-serializable Closure with Provider-based approach in InputParams - Fix eager evaluation in task descriptions using lazy Provider.map() - Add @CacheableTask annotation for better caching support - Update all task registrations to configure endpoint property - Remove all project references from task execution phase These changes enable Gradle configuration cache support for faster builds while maintaining backward compatibility. Co-Authored-By: Yuki Fujisaki <kitakore@gmail.com>
1 parent 8a7f190 commit bbae50b

File tree

4 files changed

+67
-36
lines changed

4 files changed

+67
-36
lines changed

src/main/groovy/com/deploygate/gradle/plugins/DeployGatePlugin.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class DeployGatePlugin implements Plugin<Project> {
116116
task.deployment.copyFrom(deployment)
117117
task.apkInfo.set(new DefaultPresetApkInfo(deployment.name))
118118
task.httpClient.set(httpClientProvider)
119+
task.endpoint.set(httpClientProvider.map { it.endpoint })
119120
task.usesService(httpClientProvider)
120121
task.dependsOn(loginTaskProvider)
121122
}
@@ -129,6 +130,7 @@ class DeployGatePlugin implements Plugin<Project> {
129130
task.deployment.copyFrom(deployment)
130131
task.aabInfo.set(new DefaultPresetAabInfo(deployment.name))
131132
task.httpClient.set(httpClientProvider)
133+
task.endpoint.set(httpClientProvider.map { it.endpoint })
132134
task.usesService(httpClientProvider)
133135
task.dependsOn(loginTaskProvider)
134136
}
@@ -143,6 +145,7 @@ class DeployGatePlugin implements Plugin<Project> {
143145

144146
task.apkInfo.set(variantProxy.packageApplicationTaskProvider().map {getApkInfo(it, variantProxy.name) })
145147
task.httpClient.set(httpClientProvider)
148+
task.endpoint.set(httpClientProvider.map { it.endpoint })
146149
task.usesService(httpClientProvider)
147150

148151
if (deployment.skipAssemble.get()) {
@@ -157,6 +160,7 @@ class DeployGatePlugin implements Plugin<Project> {
157160

158161
task.aabInfo.set(variantProxy.packageApplicationTaskProvider().map {getAabInfo(it, variantProxy.name, project.buildDir) })
159162
task.httpClient.set(httpClientProvider)
163+
task.endpoint.set(httpClientProvider.map { it.endpoint })
160164
task.usesService(httpClientProvider)
161165

162166
if (deployment.skipAssemble.get()) {

src/main/groovy/com/deploygate/gradle/plugins/tasks/UploadAabTask.groovy

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import org.jetbrains.annotations.VisibleForTesting
1515
abstract class UploadAabTask extends UploadArtifactTask {
1616
@NotNull
1717
@VisibleForTesting
18-
static InputParams createInputParams(@NotNull AabInfo aab, @NotNull DeploymentConfiguration deployment) {
18+
static InputParams createInputParams(@NotNull AabInfo aab, @NotNull DeploymentConfiguration deployment, @NotNull Provider<File> artifactFileProvider) {
1919
return new InputParams(
20-
variantName: aab.variantName,
21-
artifactFilePath: deployment.sourceFilePath.getOrElse(aab.aabFile?.absolutePath),
22-
isSigningReady: false,
23-
isUniversalApk: false,
24-
message: deployment.message.getOrNull(),
25-
distributionKey: deployment.distributionKey.getOrNull(),
26-
releaseNote: deployment.distributionReleaseNote.getOrNull()
20+
aab.variantName,
21+
false,
22+
false,
23+
deployment.sourceFilePath.getOrElse(aab.aabFile?.absolutePath),
24+
deployment.message.getOrNull(),
25+
deployment.distributionKey.getOrNull(),
26+
deployment.distributionReleaseNote.getOrNull(),
27+
artifactFileProvider
2728
)
2829
}
2930

@@ -39,7 +40,13 @@ abstract class UploadAabTask extends UploadArtifactTask {
3940
@Internal
4041
@Override
4142
Provider<InputParams> getInputParamsProvider() {
42-
return aabInfo.map { aab -> createInputParams(aab, deployment) }
43+
return aabInfo.map { aab ->
44+
def artifactFileProvider = deployment.sourceFilePath.map { path ->
45+
def f = new File(path ?: aab.aabFile?.absolutePath)
46+
f.exists() ? f : null
47+
}
48+
createInputParams(aab, deployment, artifactFileProvider)
49+
}
4350
}
4451

4552
@TaskAction
@@ -52,6 +59,6 @@ abstract class UploadAabTask extends UploadArtifactTask {
5259
@Internal
5360
@Override
5461
String getDescription() {
55-
return "Deploy bundled ${inputParamsProvider.get().variantName} to DeployGate"
62+
return "Deploy bundled ${inputParamsProvider.map { it.variantName }.getOrElse("variant")} to DeployGate"
5663
}
5764
}

src/main/groovy/com/deploygate/gradle/plugins/tasks/UploadApkTask.groovy

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import org.jetbrains.annotations.VisibleForTesting
1515
abstract class UploadApkTask extends UploadArtifactTask {
1616
@NotNull
1717
@VisibleForTesting
18-
static InputParams createInputParams(@NotNull ApkInfo apk, @NotNull DeploymentConfiguration deployment) {
18+
static InputParams createInputParams(@NotNull ApkInfo apk, @NotNull DeploymentConfiguration deployment, @NotNull Provider<File> artifactFileProvider) {
1919
return new InputParams(
20-
variantName: apk.variantName,
21-
artifactFilePath: deployment.sourceFilePath.getOrElse(apk.apkFile?.absolutePath),
22-
isSigningReady: apk.isSigningReady(),
23-
isUniversalApk: apk.isUniversalApk(),
24-
message: deployment.message.getOrNull(),
25-
distributionKey: deployment.distributionKey.getOrNull(),
26-
releaseNote: deployment.distributionReleaseNote.getOrNull()
20+
apk.variantName,
21+
apk.isSigningReady(),
22+
apk.isUniversalApk(),
23+
deployment.sourceFilePath.getOrElse(apk.apkFile?.absolutePath),
24+
deployment.message.getOrNull(),
25+
deployment.distributionKey.getOrNull(),
26+
deployment.distributionReleaseNote.getOrNull(),
27+
artifactFileProvider
2728
)
2829
}
2930

@@ -39,20 +40,26 @@ abstract class UploadApkTask extends UploadArtifactTask {
3940
@Internal
4041
@Override
4142
Provider<InputParams> getInputParamsProvider() {
42-
return apkInfo.map { apk -> createInputParams(apk, deployment) }
43+
return apkInfo.map { apk ->
44+
def artifactFileProvider = deployment.sourceFilePath.map { path ->
45+
def f = new File(path ?: apk.apkFile?.absolutePath)
46+
f.exists() ? f : null
47+
}
48+
createInputParams(apk, deployment, artifactFileProvider)
49+
}
4350
}
4451

4552
@Internal
4653
@Override
4754
String getDescription() {
48-
def inputParams = inputParamsProvider.get()
49-
50-
if (inputParams.isSigningReady) {
51-
return "Deploy assembled ${inputParams.variantName} to DeployGate"
52-
} else {
53-
// require signing config to build a signed APKs
54-
return "Deploy assembled ${inputParams.variantName} to DeployGate (requires valid signingConfig setting)"
55-
}
55+
return inputParamsProvider.map { inputParams ->
56+
if (inputParams.isSigningReady) {
57+
return "Deploy assembled ${inputParams.variantName} to DeployGate"
58+
} else {
59+
// require signing config to build a signed APKs
60+
return "Deploy assembled ${inputParams.variantName} to DeployGate (requires valid signingConfig setting)"
61+
}
62+
}.getOrElse("Deploy assembled variant to DeployGate")
5663
}
5764

5865
@TaskAction

src/main/groovy/com/deploygate/gradle/plugins/tasks/UploadArtifactTask.groovy

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.gradle.api.tasks.*
1717
import org.jetbrains.annotations.NotNull
1818
import org.jetbrains.annotations.Nullable
1919

20+
@CacheableTask
2021
abstract class UploadArtifactTask extends DefaultTask {
2122
static class InputParams {
2223
@Input
@@ -28,13 +29,8 @@ abstract class UploadArtifactTask extends DefaultTask {
2829
@Input
2930
boolean isUniversalApk
3031

31-
@InputFile
32-
@Optional
33-
final Closure<File> artifactFileProvider = {
34-
// workaround of OptionalInputFile: https://github.com/gradle/gradle/issues/2016
35-
def f = new File(artifactFilePath)
36-
f.exists() ? f : null
37-
}
32+
@Internal
33+
final Provider<File> artifactFileProvider
3834

3935
/**
4036
* must be an absolute path
@@ -57,7 +53,20 @@ abstract class UploadArtifactTask extends DefaultTask {
5753
@Internal
5854
@Nullable
5955
File getArtifactFile() {
60-
return artifactFileProvider.call()
56+
return artifactFileProvider.getOrNull()
57+
}
58+
59+
InputParams(String variantName, boolean isSigningReady, boolean isUniversalApk,
60+
String artifactFilePath, String message, String distributionKey,
61+
String releaseNote, Provider<File> artifactFileProvider) {
62+
this.variantName = variantName
63+
this.isSigningReady = isSigningReady
64+
this.isUniversalApk = isUniversalApk
65+
this.artifactFilePath = artifactFilePath
66+
this.message = message
67+
this.distributionKey = distributionKey
68+
this.releaseNote = releaseNote
69+
this.artifactFileProvider = artifactFileProvider
6170
}
6271
}
6372

@@ -70,6 +79,10 @@ abstract class UploadArtifactTask extends DefaultTask {
7079
@Internal
7180
final Property<HttpClient> httpClient
7281

82+
@Input
83+
@Optional
84+
abstract Property<String> getEndpoint()
85+
7386
@OutputFile
7487
final Provider<RegularFile> response
7588

@@ -116,7 +129,7 @@ abstract class UploadArtifactTask extends DefaultTask {
116129
def hasNotified = httpClient.get().lifecycleNotificationClient.notifyOnSuccessOfArtifactUpload(uploadResponse.typedResponse.application.path)
117130

118131
if (!hasNotified && (Config.shouldOpenAppDetailAfterUpload() || uploadResponse.typedResponse.application.revision == 1)) {
119-
BrowserUtils.openBrowser "${project.deploygate.endpoint}${uploadResponse.typedResponse.application.path}"
132+
BrowserUtils.openBrowser "${endpoint.get()}${uploadResponse.typedResponse.application.path}"
120133
}
121134
} catch (Throwable e) {
122135
logger.debug(e.message, e)

0 commit comments

Comments
 (0)