11package love.forte.plugin.suspendtrans.gradle
22
3- import BuildConfig
43import love.forte.plugin.suspendtrans.CliOptions
54import org.gradle.api.Project
65import org.gradle.api.provider.Provider
@@ -22,13 +21,13 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin {
2221 return kotlinCompilation.target.project.plugins.hasPlugin(SuspendTransformGradlePlugin ::class .java)
2322 }
2423
25- override fun getCompilerPluginId (): String = BuildConfig .KOTLIN_PLUGIN_ID
24+ override fun getCompilerPluginId (): String = SuspendTransPluginConstants .KOTLIN_PLUGIN_ID
2625
2726 override fun getPluginArtifact (): SubpluginArtifact {
2827 return SubpluginArtifact (
29- groupId = BuildConfig .KOTLIN_PLUGIN_GROUP ,
30- artifactId = BuildConfig .KOTLIN_PLUGIN_NAME ,
31- version = BuildConfig .KOTLIN_PLUGIN_VERSION
28+ groupId = SuspendTransPluginConstants .KOTLIN_PLUGIN_GROUP ,
29+ artifactId = SuspendTransPluginConstants .KOTLIN_PLUGIN_NAME ,
30+ version = SuspendTransPluginConstants .KOTLIN_PLUGIN_VERSION
3231 )
3332 }
3433
@@ -42,12 +41,12 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin {
4241// val dependencies = project.dependencies
4342// dependencies.add(
4443// "compileOnly",
45- // "${BuildConfig .ANNOTATION_GROUP}:${BuildConfig .ANNOTATION_NAME}:${BuildConfig .ANNOTATION_VERSION}"
44+ // "${SuspendTransPluginConstants .ANNOTATION_GROUP}:${SuspendTransPluginConstants .ANNOTATION_NAME}:${SuspendTransPluginConstants .ANNOTATION_VERSION}"
4645// )
4746// if (extension.includeRuntime) {
4847// dependencies.add(
4948// extension.runtimeConfigurationName,
50- // "${BuildConfig .RUNTIME_GROUP}:${BuildConfig .RUNTIME_NAME}:${BuildConfig .RUNTIME_VERSION}"
49+ // "${SuspendTransPluginConstants .RUNTIME_GROUP}:${SuspendTransPluginConstants .RUNTIME_NAME}:${SuspendTransPluginConstants .RUNTIME_VERSION}"
5150// )
5251// }
5352
@@ -71,18 +70,23 @@ private fun Project.configureDependencies() {
7170 fun Project.include (platform : Platform , conf : SuspendTransformGradleExtension ) {
7271 if (conf.includeAnnotation) {
7372 val notation = getDependencyNotation(
74- BuildConfig .ANNOTATION_GROUP ,
75- BuildConfig .ANNOTATION_NAME ,
73+ SuspendTransPluginConstants .ANNOTATION_GROUP ,
74+ SuspendTransPluginConstants .ANNOTATION_NAME ,
7675 platform,
7776 conf.annotationDependencyVersion
7877 )
79- dependencies.add(conf.annotationConfigurationName, notation)
78+ if (platform == Platform .JVM ) {
79+ dependencies.add(conf.annotationConfigurationName, notation)
80+ } else {
81+ // JS, native 似乎不支持其他的 name,例如 compileOnly
82+ dependencies.add(" implementation" , notation)
83+ }
8084 dependencies.add(" testImplementation" , notation)
8185 }
8286 if (conf.includeRuntime) {
8387 val notation = getDependencyNotation(
84- BuildConfig .RUNTIME_GROUP ,
85- BuildConfig .RUNTIME_NAME ,
88+ SuspendTransPluginConstants .RUNTIME_GROUP ,
89+ SuspendTransPluginConstants .RUNTIME_NAME ,
8690 platform,
8791 conf.runtimeDependencyVersion
8892 )
@@ -129,45 +133,48 @@ fun Project.withPluginWhenEvaluatedConf(
129133
130134fun Project.configureMultiplatformDependency (conf : SuspendTransformGradleExtension ) {
131135 if (rootProject.getBooleanProperty(" kotlin.mpp.enableGranularSourceSetsMetadata" )) {
132- val mainSourceSets = project.extensions.getByType(KotlinMultiplatformExtension ::class .java).sourceSets
133- .getByName(KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
134- val testSourceSets = project.extensions.getByType(KotlinMultiplatformExtension ::class .java).sourceSets
135- .getByName(KotlinSourceSet .COMMON_TEST_SOURCE_SET_NAME )
136+ val multiplatformExtensions = project.extensions.getByType(KotlinMultiplatformExtension ::class .java)
136137
138+ val commonMainSourceSets =
139+ multiplatformExtensions.sourceSets.getByName(KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
140+ val commonTestSourceSets =
141+ multiplatformExtensions.sourceSets.getByName(KotlinSourceSet .COMMON_TEST_SOURCE_SET_NAME )
137142
138143 if (conf.includeAnnotation) {
139144 val notation = getDependencyNotation(
140- BuildConfig .ANNOTATION_GROUP ,
141- BuildConfig .ANNOTATION_NAME ,
145+ SuspendTransPluginConstants .ANNOTATION_GROUP ,
146+ SuspendTransPluginConstants .ANNOTATION_NAME ,
142147 Platform .MULTIPLATFORM ,
143148 conf.annotationDependencyVersion
144149 )
145- dependencies.add(mainSourceSets .compileOnlyConfigurationName, notation)
146- dependencies.add(testSourceSets .implementationConfigurationName, notation)
150+ dependencies.add(commonMainSourceSets .compileOnlyConfigurationName, notation)
151+ dependencies.add(commonTestSourceSets .implementationConfigurationName, notation)
147152 }
148153
149154 if (conf.includeRuntime) {
150155 val notation = getDependencyNotation(
151- BuildConfig .RUNTIME_GROUP ,
152- BuildConfig .RUNTIME_NAME ,
156+ SuspendTransPluginConstants .RUNTIME_GROUP ,
157+ SuspendTransPluginConstants .RUNTIME_NAME ,
153158 Platform .MULTIPLATFORM ,
154159 conf.annotationDependencyVersion
155160 )
156- dependencies.add(mainSourceSets .implementationConfigurationName, notation)
157- dependencies.add(testSourceSets .implementationConfigurationName, notation)
161+ dependencies.add(commonMainSourceSets .implementationConfigurationName, notation)
162+ dependencies.add(commonTestSourceSets .implementationConfigurationName, notation)
158163 }
159164
160165 // For each source set that is only used in Native compilations, add an implementation dependency so that it
161166 // gets published and is properly consumed as a transitive dependency:
162167 sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
163- val isSharedNativeSourceSet = compilations.all {
168+ val isSharedSourceSet = compilations.all {
164169 it.platformType == KotlinPlatformType .common || it.platformType == KotlinPlatformType .native
170+ || it.platformType == KotlinPlatformType .js || it.platformType == KotlinPlatformType .wasm
165171 }
166- if (isSharedNativeSourceSet) {
172+
173+ if (isSharedSourceSet) {
167174 if (conf.includeAnnotation) {
168175 val notation = getDependencyNotation(
169- BuildConfig .ANNOTATION_GROUP ,
170- BuildConfig .ANNOTATION_NAME ,
176+ SuspendTransPluginConstants .ANNOTATION_GROUP ,
177+ SuspendTransPluginConstants .ANNOTATION_NAME ,
171178 Platform .MULTIPLATFORM ,
172179 conf.annotationDependencyVersion
173180 )
@@ -177,8 +184,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi
177184
178185 if (conf.includeRuntime) {
179186 val notation = getDependencyNotation(
180- BuildConfig .RUNTIME_GROUP ,
181- BuildConfig .RUNTIME_NAME ,
187+ SuspendTransPluginConstants .RUNTIME_GROUP ,
188+ SuspendTransPluginConstants .RUNTIME_NAME ,
182189 Platform .MULTIPLATFORM ,
183190 conf.annotationDependencyVersion
184191 )
@@ -215,8 +222,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi
215222 }
216223
217224 val notation = getDependencyNotation(
218- BuildConfig .ANNOTATION_GROUP ,
219- BuildConfig .ANNOTATION_NAME ,
225+ SuspendTransPluginConstants .ANNOTATION_GROUP ,
226+ SuspendTransPluginConstants .ANNOTATION_NAME ,
220227 platform,
221228 conf.annotationDependencyVersion
222229 )
@@ -227,8 +234,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi
227234 val configurationName = sourceSet.implementationConfigurationName
228235
229236 val notation = getDependencyNotation(
230- BuildConfig .RUNTIME_GROUP ,
231- BuildConfig .RUNTIME_NAME ,
237+ SuspendTransPluginConstants .RUNTIME_GROUP ,
238+ SuspendTransPluginConstants .RUNTIME_NAME ,
232239 platform,
233240 conf.runtimeDependencyVersion
234241 )
0 commit comments