@@ -58,23 +58,25 @@ class Foo {
58
58
return " Hello"
59
59
}
60
60
@Api4Js // RequiresOptIn annotation, provide warnings to Kotlin
61
- fun waitAndGetBlocking (): Promise <String > = runInAsync { waitAndGet() } // 'runInBlocking ' from the runtime provided by the plugin
61
+ fun waitAndGetBlocking (): Promise <String > = runInAsync { waitAndGet() } // 'runInAsync ' from the runtime provided by the plugin
62
62
}
63
63
```
64
64
65
65
> JS platform target not supported yet. see: [ KT-53993] ( https://youtrack.jetbrains.com/issue/KT-53993 )
66
66
67
-
68
67
## Usage
69
68
### Gradle
70
69
71
- ** Way 1:**
70
+ ** Using the [ plugins DSL] ( https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block ) :**
71
+
72
+ <details open >
73
+ <summary >Kotlin</summary >
72
74
73
75
_ build.gradle.kts_
74
76
75
77
``` kotlin
76
- plugins {
77
- kotlin( " jvm" ) // or.. ?
78
+ plugins {
79
+ id( " org.jetbrains.kotlin. jvm" ) version " KOTLIN_VERSION " // or js? or multiplatform ?
78
80
id(" love.forte.plugin.suspend-transform" ) version " $PLUGIN_VERSION "
79
81
// other...
80
82
}
@@ -94,7 +96,43 @@ suspendTransform {
94
96
}
95
97
```
96
98
97
- ** Way 2:**
99
+ </details >
100
+
101
+ <details >
102
+ <summary >Groovy</summary >
103
+
104
+ _ build.gradle_
105
+
106
+ ``` groovy
107
+ plugins {
108
+ id "org.jetbrains.kotlin.jvm" // or js? or multiplatform?
109
+ id "love.forte.plugin.suspend-transform" version "$PLUGIN_VERSION"
110
+ // other...
111
+ }
112
+
113
+ // other...
114
+
115
+ // config it.
116
+ suspendTransform {
117
+ enabled = true // default: true
118
+ includeRuntime = true // default: true
119
+ jvm {
120
+ // ...
121
+ }
122
+ js {
123
+ // ...
124
+ }
125
+ }
126
+ ```
127
+
128
+ </details >
129
+
130
+
131
+
132
+ ** Using [ legacy plugin application] ( https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application ) :**
133
+
134
+ <details open >
135
+ <summary >Kotlin</summary >
98
136
99
137
_ build.gradle.kts_
100
138
@@ -109,8 +147,8 @@ buildscript {
109
147
}
110
148
}
111
149
112
- plugins {
113
- kotlin( " jvm" ) // or.. ?
150
+ plugins {
151
+ id( " org.jetbrains.kotlin. jvm" ) // or js? or multiplatform ?
114
152
id(" love.forte.plugin.suspend-transform" )
115
153
// other...
116
154
}
@@ -130,10 +168,63 @@ suspendTransform {
130
168
}
131
169
```
132
170
171
+ </details >
172
+
173
+ <details >
174
+ <summary >Groovy</summary >
175
+
176
+ _ build.gradle_
177
+
178
+ ``` groovy
179
+ buildscript {
180
+ repositories {
181
+ maven {
182
+ url "https://plugins.gradle.org/m2/"
183
+ }
184
+ }
185
+ dependencies {
186
+ classpath "love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:$VERSION"
187
+ }
188
+ }
189
+
190
+
191
+
192
+ plugins {
193
+ id "org.jetbrains.kotlin.jvm" // or js? or multiplatform?
194
+ id "love.forte.plugin.suspend-transform"
195
+ // other...
196
+ }
197
+
198
+ // other...
199
+
200
+ // config it.
201
+ suspendTransform {
202
+ enabled = true // default: true
203
+ includeRuntime = true // default: true
204
+ jvm {
205
+ // ...
206
+ }
207
+ js {
208
+ // ...
209
+ }
210
+ }
211
+ ```
212
+
213
+ </details >
214
+
133
215
### Maven
134
216
135
217
> Not supported yet.
136
218
219
+ ## Cautions
220
+
221
+ ### Gradle JVM
222
+
223
+ Gradle JVM must be JDK11+
224
+
225
+ ### JS platform
226
+
227
+ JS platform target not supported yet. see: [ KT-53993] ( https://youtrack.jetbrains.com/issue/KT-53993 )
137
228
138
229
## Effect
139
230
@@ -176,7 +267,7 @@ class Bar {
176
267
177
268
** compiled:**
178
269
179
- > Simplified from decompiled results.
270
+ > _ Simplified from decompiled results._
180
271
181
272
``` kotlin
182
273
import love.forte.plugin.suspendtrans.annotation.JvmAsync
@@ -287,3 +378,108 @@ class Bar {
287
378
fun noTrans (): Int { /* compiled code */ }
288
379
}
289
380
```
381
+
382
+ ## Custom config
383
+
384
+ ``` kotlin
385
+ plugin {
386
+ id(" love.forte.plugin.suspend-transform" ) version " $VERSION "
387
+ }
388
+
389
+
390
+ suspendTransform {
391
+ // enabled suspend transform plugin
392
+ enabled = true
393
+ // include 'love.forte.plugin.suspend-transform:suspend-transform-runtime' to the runtime environment
394
+ includeRuntime = true
395
+ // the configuration name for including 'love.forte.plugin.suspend-transform:suspend-transform-runtime'
396
+ runtimeConfigurationName = " implementation"
397
+
398
+ // jvm platform target config
399
+ jvm {
400
+ // jvm blocking annotation. default: @JvmBlocking
401
+ jvmBlockingMarkAnnotation.apply {
402
+ annotationName = " love.forte.plugin.suspendtrans.annotation.JvmBlocking"
403
+ baseNameProperty = " baseName"
404
+ suffixProperty = " suffix"
405
+ asPropertyProperty = " asProperty"
406
+ }
407
+
408
+ // jvm async annotation. default: @JvmAsync
409
+ jvmAsyncMarkAnnotation.apply {
410
+ annotationName = " love.forte.plugin.suspendtrans.annotation.JvmAsync"
411
+ baseNameProperty = " baseName"
412
+ suffixProperty = " suffix"
413
+ asPropertyProperty = " asProperty"
414
+ }
415
+
416
+ // jvm blocking function.
417
+ // The function signature must satisfy: fun <T> <fun-name>(block: suspend () -> T): T
418
+ jvmBlockingFunctionName = " love.forte.plugin.suspendtrans.runtime.\$ runInBlocking$"
419
+
420
+ // jvm async function.
421
+ // The function signature must satisfy: fun <T> <fun-name>(block: suspend () -> T): CompletableFuture<T>
422
+ jvmAsyncFunctionName = " love.forte.plugin.suspendtrans.runtime.\$ runInAsync$"
423
+
424
+ // annotations that to be included to the synthetic blocking functions
425
+ syntheticBlockingFunctionIncludeAnnotations = listOf (
426
+ SuspendTransformConfiguration .IncludeAnnotation (" love.forte.plugin.suspendtrans.annotation.Api4J" )
427
+ )
428
+
429
+ // annotations that to be included to the synthetic async functions
430
+ syntheticAsyncFunctionIncludeAnnotations = listOf (
431
+ SuspendTransformConfiguration .IncludeAnnotation (" love.forte.plugin.suspendtrans.annotation.Api4J" )
432
+ )
433
+
434
+ // copy the annotations from source function to the synthetic blocking function
435
+ copyAnnotationsToSyntheticBlockingFunction = true
436
+
437
+ // copy the annotations from source function to the synthetic async function
438
+ copyAnnotationsToSyntheticAsyncFunction = true
439
+
440
+ // if 'copyAnnotationsToSyntheticBlockingFunction == true',
441
+ // list of annotations to be excluded in the copy process
442
+ copyAnnotationsToSyntheticBlockingFunctionExcludes = listOf (
443
+ SuspendTransformConfiguration .ExcludeAnnotation (" kotlin.jvm.JvmSynthetic" )
444
+ )
445
+
446
+ // if 'copyAnnotationsToSyntheticAsyncFunction == true',
447
+ // list of annotations to be excluded in the copy process
448
+ copyAnnotationsToSyntheticAsyncFunctionExcludes = listOf (
449
+ SuspendTransformConfiguration .ExcludeAnnotation (" kotlin.jvm.JvmSynthetic" )
450
+ )
451
+ }
452
+
453
+ js {
454
+ // Roughly similar to what is in 'jvm'
455
+ }
456
+
457
+
458
+ }
459
+ ```
460
+
461
+ ## License
462
+
463
+ see [ LICENSE] ( LICENSE ) .
464
+
465
+ ``` text
466
+ Copyright (c) 2022 ForteScarlet
467
+
468
+ Permission is hereby granted, free of charge, to any person obtaining a copy
469
+ of this software and associated documentation files (the "Software"), to deal
470
+ in the Software without restriction, including without limitation the rights
471
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
472
+ copies of the Software, and to permit persons to whom the Software is
473
+ furnished to do so, subject to the following conditions:
474
+
475
+ The above copyright notice and this permission notice shall be included in all
476
+ copies or substantial portions of the Software.
477
+
478
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
479
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
480
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
481
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
482
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
483
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
484
+ SOFTWARE.
485
+ ```
0 commit comments