Skip to content

Commit ff8fbc5

Browse files
committed
connectors.gradle.kts: fix unwarranted error from updateJson task during configure time
1 parent 22ace25 commit ff8fbc5

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

firebase-dataconnect/connectors/connectors.gradle.kts

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,81 @@ tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
125125
jsonFile.set(
126126
project.layout.projectDirectory.file(
127127
"../gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
128-
"plugin/DataConnectExecutableVersions.json"
128+
"plugin/DataConnectExecutableVersions.json"
129129
)
130130
)
131131
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))
132132

133-
val singleVersion: String? = project.providers.gradleProperty("version").orNull
133+
val propertyNames = object {
134+
val version = "version"
135+
val versions = "versions"
136+
val updateMode = "updateMode"
137+
val defaultVersion = "defaultVersion"
138+
}
139+
140+
val singleVersion: String? = project.providers.gradleProperty(propertyNames.version).orNull
134141
val multipleVersions: List<String>? =
135-
project.providers.gradleProperty("versions").orNull?.split(',')
142+
project.providers.gradleProperty(propertyNames.versions).orNull?.split(',')
136143
versions.set(
137144
buildList {
138145
singleVersion?.let { add(it) }
139146
multipleVersions?.let { addAll(it) }
140-
if (isEmpty()) {
141-
throw Exception("bm6d5ezxzd 'version' or 'versions' property must be specified")
142-
}
143147
}
144148
)
145149

150+
doFirst {
151+
if (versions.get().isEmpty()) {
152+
logger.warn(
153+
"WARNING: no '${propertyNames.version}' or '${propertyNames.versions}' specified " +
154+
"for task '$name'; no versions will be added to ${jsonFile.get()}. " +
155+
"Try specifying something like '-P${propertyNames.version}=1.2.3' or " +
156+
"'-P${propertyNames.versions}=1.2.3,4.5.6' on the gradle command line " +
157+
"if you want to add versions (warning code bm6d5ezxzd)"
158+
)
159+
}
160+
}
161+
146162
updateMode.set(
147-
project.providers.gradleProperty("updateMode").map {
163+
project.providers.gradleProperty(propertyNames.updateMode).map {
148164
when (it) {
149165
"overwrite" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Overwrite
150166
"update" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Update
151167
else ->
152-
throw Exception("ahe4zadcjs 'updateMode' must be 'overwrite' or 'update', but got: $it")
168+
throw Exception(
169+
"Invalid '${propertyNames.updateMode}' specified for task '$name': $it. " +
170+
"Valid values are 'update' and 'overwrite'. " +
171+
"Try specifying '-P${propertyNames.updateMode}=update' or " +
172+
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line. " +
173+
"(error code v2e3cfqbnf)"
174+
)
153175
}
154176
}
155177
)
156178

157-
defaultVersion.set(project.providers.gradleProperty("defaultVersion"))
179+
doFirst {
180+
if (!updateMode.isPresent) {
181+
logger.warn(
182+
"WARNING: no '${propertyNames.updateMode}' specified for task '$name'; " +
183+
"the default update mode of 'update' will be used when updating ${jsonFile.get()}. " +
184+
"Try specifying '-P${propertyNames.updateMode}=update' or " +
185+
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line " +
186+
"if you want a different update mode, or just want to be explicit about " +
187+
"which update mode is in effect (warning code tjyscqmdne)"
188+
)
189+
}
190+
}
191+
192+
defaultVersion.set(project.providers.gradleProperty(propertyNames.defaultVersion))
193+
194+
doFirst {
195+
if (!defaultVersion.isPresent) {
196+
logger.warn(
197+
"WARNING: no '${propertyNames.defaultVersion}' specified for task '$name'; " +
198+
"the default version will not be updated in ${jsonFile.get()}. " +
199+
"Try specifying something like '-P${propertyNames.defaultVersion}=1.2.3' " +
200+
"on the gradle command line if you want to update the default version " +
201+
"(warning code vqrbrktx9f)"
202+
)
203+
}
204+
}
158205
}

0 commit comments

Comments
 (0)