Skip to content

Commit 8889faf

Browse files
authored
[plugin] refactor Gradle tasks to use Worker API (ExpediaGroup#1002)
Updating all Gradle tasks to use Worker API that allows us to minimize the number of plugin dependencies through classpath isolation. Plugin has `compileOnly` dependencies on `graphql-kotlin` modules (`client-generator` which is renamed `plugin-core` module and `sdl-generator`). New `WorkAction`s will use classpath isolation with custom configuration that includes necessary dependencies to run the actions. Updated build scan (from example gradle client): https://scans.gradle.com/s/znufum5lj75lg/build-dependencies
1 parent 1583066 commit 8889faf

File tree

85 files changed

+866
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+866
-437
lines changed

docs/plugins/gradle-plugin-examples.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ if you would like to use WebClient implementation instead you need to specify `G
136136

137137
```kotlin
138138
// build.gradle.kts
139-
import com.expediagroup.graphql.plugin.generator.GraphQLClientType
139+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
140140
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateClientTask
141141

142142
val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
@@ -150,8 +150,10 @@ val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
150150

151151
```groovy
152152
//build.gradle
153+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
154+
153155
graphqlGenerateClient {
154-
clientType = com.expediagroup.graphql.plugin.generator.GraphQLClientType.KTOR
156+
clientType = GraphQLClientType.KTOR
155157
packageName = "com.example.generated"
156158
schemaFileName = "mySchema.graphql"
157159
}
@@ -191,23 +193,26 @@ Afterwards we need to configure our plugin to use this custom converter
191193

192194
```kotlin
193195
// build.gradle.kts
196+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
194197
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGenerateClientTask
195198

196199
val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
197200
packageName.set("com.example.generated")
198201
schemaFileName.set("mySchema.graphql")
199-
converters.put("UUID", ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter"))
202+
customScalars.add(GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
200203
}
201204
```
202205

203206
<!--Groovy-->
204207

205208
```groovy
206209
//build.gradle
210+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
211+
207212
graphqlGenerateClient {
208213
packageName = "com.example.generated"
209214
schemaFileName = "mySchema.graphql"
210-
converters["UUID"] = new com.expediagroup.graphql.plugin.generator.ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter")
215+
customScalars.add(new GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
211216
}
212217
```
213218

@@ -331,9 +336,8 @@ the GraphQL Ktor client code based on the provided query.
331336

332337
```kotlin
333338
// build.gradle.kts
334-
import com.expediagroup.graphql.plugin.config.TimeoutConfig
335-
import com.expediagroup.graphql.plugin.generator.GraphQLClientType
336-
import com.expediagroup.graphql.plugin.generator.ScalarConverterMapping
339+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
340+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
337341
import com.expediagroup.graphql.plugin.gradle.graphql
338342

339343
graphql {
@@ -343,7 +347,7 @@ graphql {
343347
// optional configuration
344348
allowDeprecatedFields = true
345349
clientType = GraphQLClientType.KTOR
346-
converters = mapOf("UUID" to ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter"))
350+
customScalars = listOf(GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
347351
headers = mapOf("X-Custom-Header" to "My-Custom-Header")
348352
queryFiles = listOf(file("${project.projectDir}/src/main/resources/queries/MyQuery.graphql"))
349353
timeout {
@@ -358,24 +362,24 @@ Above configuration is equivalent to the following
358362

359363
```kotlin
360364
// build.gradle.kts
361-
import com.expediagroup.graphql.plugin.config.TimeoutConfig
362-
import com.expediagroup.graphql.plugin.generator.GraphQLClientType
363-
import com.expediagroup.graphql.plugin.generator.ScalarConverterMapping
365+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
366+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
367+
import com.expediagroup.graphql.plugin.gradle.config.TimeoutConfiguration
364368
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLDownloadSDLTask
365369
import com.expediagroup.graphql.plugin.gradle.tasks.GraphQLIntrospectSchemaTask
366370

367371
val graphqlDownloadSDL by tasks.getting(GraphQLDownloadSDLTask::class) {
368372
endpoint.set("http://localhost:8080/sdl")
369373
headers.put("X-Custom-Header", "My-Custom-Header")
370-
timeoutConfig.set(TimeoutConfig(connect = 10_000, read = 30_000))
374+
timeoutConfig.set(TimeoutConfiguration(connect = 10_000, read = 30_000))
371375
}
372376
val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
373377
packageName.set("com.example.generated")
374378
schemaFile.set(graphqlDownloadSDL.outputFile)
375379
// optional
376380
allowDeprecatedFields.set(true)
377381
clientType.set(GraphQLClientType.KTOR)
378-
converters.put("UUID", ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter"))
382+
customScalars.add(GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
379383
queryFiles.from("${project.projectDir}/src/main/resources/queries/MyQuery.graphql")
380384

381385
dependsOn("graphqlDownloadSDL")
@@ -386,19 +390,22 @@ val graphqlGenerateClient by tasks.getting(GraphQLGenerateClientTask::class) {
386390

387391
```groovy
388392
// build.gradle
393+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
394+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
395+
389396
graphql {
390397
client {
391398
sdlEndpoint = "http://localhost:8080/sdl"
392399
packageName = "com.example.generated"
393400
// optional configuration
394401
allowDeprecatedFields = true
395-
clientType = com.expediagroup.graphql.plugin.generator.GraphQLClientType.KTOR
396-
converters = ["UUID" : new com.expediagroup.graphql.plugin.generator.ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter")]
402+
clientType = GraphQLClientType.KTOR
403+
customScalars = [new GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter")]
397404
headers = ["X-Custom-Header" : "My-Custom-Header"]
398405
queryFiles = [file("${project.projectDir}/src/main/resources/queries/MyQuery.graphql")]
399406
timeout { t ->
400-
t.connect = 10_000
401-
t.read = 30_000
407+
t.connect = 10000
408+
t.read = 30000
402409
}
403410
}
404411
}
@@ -408,18 +415,22 @@ Above configuration is equivalent to the following
408415

409416
```groovy
410417
//build.gradle
418+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
419+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
420+
import com.expediagroup.graphql.plugin.gradle.config.TimeoutConfiguration
421+
411422
graphqlDownloadSDL {
412423
endpoint = "http://localhost:8080/sdl"
413424
headers["X-Custom-Header"] = "My-Custom-Header"
414-
timeoutConfig = new com.expediagroup.graphql.plugin.config.TimeoutConfig(10000, 30000)
425+
timeoutConfig = new TimeoutConfiguration(10000, 30000)
415426
}
416427
graphqlGenerateClient {
417428
packageName = "com.example.generated"
418429
schemaFile = graphqlDownloadSDL.outputFile
419430
// optional
420431
allowDeprecatedFields = true
421-
clientType = com.expediagroup.graphql.plugin.generator.GraphQLClientType.KTOR
422-
converters["UUID"] = new com.expediagroup.graphql.plugin.generator.ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter")
432+
clientType = GraphQLClientType.KTOR
433+
customScalars.add(new GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
423434
queryFiles.from("${project.projectDir}/src/main/resources/queries/MyQuery.graphql")
424435
425436
dependsOn graphqlDownloadSDL

docs/plugins/gradle-plugin.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ tasks.
8686

8787
```kotlin
8888
// build.gradle.kts
89-
import com.expediagroup.graphql.plugin.generator.GraphQLClientType
89+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
90+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
9091
import com.expediagroup.graphql.plugin.gradle.graphql
9192

9293
graphql {
@@ -95,8 +96,8 @@ graphql {
9596
allowDeprecatedFields = false
9697
// Type of GraphQL client implementation to generate.
9798
clientType = GraphQLClientType.DEFAULT
98-
// Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
99-
converters = mapOf("UUID" to ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter"))
99+
// List of custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
100+
customScalars = listOf(GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter"))
100101
// GraphQL server endpoint that will be used to for running introspection queries. Alternatively you can download schema directly from `sdlEndpoint`.
101102
endpoint = "http://localhost:8080/graphql"
102103
// Optional HTTP headers to be specified on an introspection query or SDL request.
@@ -129,14 +130,17 @@ graphql {
129130

130131
```groovy
131132
// build.gradle
133+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLClientType
134+
import com.expediagroup.graphql.plugin.gradle.config.GraphQLScalar
135+
132136
graphql {
133137
client {
134138
// Boolean flag indicating whether or not selection of deprecated fields is allowed.
135139
allowDeprecatedFields = false
136140
// Type of GraphQL client implementation to generate.
137-
clientType = com.expediagroup.graphql.plugin.generator.GraphQLClientType.DEFAULT
138-
// Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
139-
converters = ["UUID" : new com.expediagroup.graphql.plugin.generator.ScalarConverterMapping("java.util.UUID", "com.example.UUIDScalarConverter")]
141+
clientType = GraphQLClientType.DEFAULT
142+
// List of custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values.
143+
customScalars = [new GraphQLScalar("UUID", "java.util.UUID", "com.example.UUIDScalarConverter")]
140144
// GraphQL server endpoint that will be used to for running introspection queries. Alternatively you can download schema directly from `sdlEndpoint`.
141145
endpoint = "http://localhost:8080/graphql"
142146
// Optional HTTP headers to be specified on an introspection query or SDL request.
@@ -200,7 +204,7 @@ resulting generated code will be automatically added to the project main source
200204
| -------- | ---- | -------- | ----------- |
201205
| `allowDeprecatedFields` | Boolean | | Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:** `false`.<br/>**Command line property is**: `allowDeprecatedFields`. |
202206
| `clientType` | GraphQLClientType | | Enum value that specifies target GraphQL client type implementation.<br/>**Default value is:** `GraphQLClientType.DEFAULT`. |
203-
| `converters` | Map<String, ScalarConverter> | | Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
207+
| `customScalars` | List<GraphQLScalar> | | List of custom GraphQL scalar to converter mappings containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
204208
| `packageName` | String | yes | Target package name for generated code.<br/>**Command line property is**: `packageName`. |
205209
| `queryFiles` | FileCollection | | List of query files to be processed. Instead of a list of files to be processed you can specify `queryFileDirectory` directory instead. If this property is specified it will take precedence over the corresponding directory property. |
206210
| `queryFileDirectory` | String | | Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:** `src/main/resources`.<br/>**Command line property is**: `queryFileDirectory`. |
@@ -236,7 +240,7 @@ test source set.
236240
| -------- | ---- | -------- | ----------- |
237241
| `allowDeprecatedFields` | Boolean | | Boolean flag indicating whether selection of deprecated fields is allowed or not.<br/>**Default value is:** `false`.<br/>**Command line property is**: `allowDeprecatedFields`. |
238242
| `clientType` | GraphQLClientType | | Enum value that specifies target GraphQL client type implementation.<br/>**Default value is:** `GraphQLClientType.DEFAULT`. |
239-
| `converters` | Map<String, ScalarConverter> | | Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
243+
| `customScalars` | List<GraphQLScalar> | | List of custom GraphQL scalar to converter mappings containing information about corresponding Java type and converter that should be used to serialize/deserialize values. |
240244
| `packageName` | String | yes | Target package name for generated code.<br/>**Command line property is**: `packageName`. |
241245
| `queryFiles` | FileCollection | | List of query files to be processed. Instead of a list of files to be processed you can specify `queryFileDirectory` directory instead. If this property is specified it will take precedence over the corresponding directory property. |
242246
| `queryFileDirectory` | String | | Directory file containing GraphQL queries. Instead of specifying a directory you can also specify list of query file by using `queryFiles` property instead.<br/>**Default value is:** `src/test/resources`.<br/>**Command line property is**: `queryFileDirectory`. |

docs/plugins/maven-plugin-examples.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,17 @@ Afterwards we need to configure our plugin to use this custom converter
172172
</goals>
173173
<configuration>
174174
<allowDeprecatedFields>false</allowDeprecatedFields>
175-
<converters>
176-
<!-- custom scalar UUID type -->
177-
<UUID>
175+
<customScalars>
176+
<customScalar>
177+
<!-- custom scalar UUID type -->
178+
<scalar>UUID</scalar>
178179
<!-- fully qualified Java class name of a custom scalar type -->
179180
<type>java.util.UUID</type>
180181
<!-- fully qualified Java class name of a custom com.expediagroup.graphql.client.converter.ScalarConverter
181182
used to convert to/from raw JSON and scalar type -->
182183
<converter>com.example.UUIDScalarConverter</converter>
183-
</UUID>
184-
</converters>
184+
</customScalar>
185+
</customScalars>
185186
<packageName>com.example.generated</packageName>
186187
<schemaFile>mySchema.graphql</schemaFile>
187188
</configuration>
@@ -279,16 +280,17 @@ the GraphQL client code based on the provided query.
279280
<!-- optional configuration below -->
280281
<schemaFile>${project.build.directory}/mySchema.graphql</schemaFile>
281282
<allowDeprecatedFields>true</allowDeprecatedFields>
282-
<converters>
283-
<!-- custom scalar UUID type -->
284-
<UUID>
283+
<customScalars>
284+
<customScalar>
285+
<!-- custom scalar UUID type -->
286+
<scalar>UUID</scalar>
285287
<!-- fully qualified Java class name of a custom scalar type -->
286288
<type>java.util.UUID</type>
287289
<!-- fully qualified Java class name of a custom com.expediagroup.graphql.client.converter.ScalarConverter
288290
used to convert to/from raw JSON and scalar type -->
289291
<converter>com.example.UUIDScalarConverter</converter>
290-
</UUID>
291-
</converters>
292+
</customScalar>
293+
</customScalars>
292294
<headers>
293295
<X-Custom-Header>My-Custom-Header</X-Custom-Header>
294296
</headers>

0 commit comments

Comments
 (0)