ForteScarlet / kotlin-suspend-transform-compiler-plugin

A Kotlin compiler plugin for transforming suspend functions to platform-compatible non-suspend functions, such as the JVM Blocking API and CompletableFuture or JS Promise, etc. 🐱
MIT License
36 stars 3 forks source link

Gradle warning with beta version: 2.0.20-Beta1-0.9.1 #59

Closed waltkb closed 4 months ago

waltkb commented 4 months ago

Just a warning I saw happening with the latest beta version:

When including the plugin id("love.forte.plugin.suspend-transform") version "2.0.20-Beta1-0.9.1, this Gradle warning is shown:

A compileOnly dependency is used in targets: Kotlin/JS.
Dependencies:
    - love.forte.plugin.suspend-transform:suspend-transform-annotation:2.0.20-Beta1-0.9.1 (source sets: jsMain)

Using compileOnly dependencies in these targets is not currently supported, because compileOnly dependencies must be present during the compilation of projects that depend on this project.

To ensure consistent compilation behaviour, compileOnly dependencies should be exposed as api dependencies.

Example:

    kotlin {
        sourceSets {
            nativeMain {
                dependencies {
                    compileOnly("org.example:lib:1.2.3")
                    // additionally add the compileOnly dependency as an api dependency:
                    api("org.example:lib:1.2.3")
                }
            }
        }
    }

This warning can be suppressed in gradle.properties:

    kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
ForteScarlet commented 4 months ago

This seems to be because of the compileOnly dependency added to commonMain, try tweaking annotationConfigurationName in the config:

suspendTransform {
    annotationConfigurationName = "implementation"
}
waltkb commented 4 months ago

It continues to happen with this configuration:

suspendTransform {
    enabled = true
    includeRuntime = true
    useDefault()
    annotationConfigurationName = "implementation"
}
> Configure project :waltid-libraries:waltid-crypto
w: A compileOnly dependency is used in targets: Kotlin/JS.
Dependencies:
    - love.forte.plugin.suspend-transform:suspend-transform-annotation:2.0.20-Beta1-0.9.1 (source sets: jsMain)

Using compileOnly dependencies in these targets is not currently supported, because compileOnly dependencies must be present during the compilation of projects that depend on this project.

To ensure consistent compilation behaviour, compileOnly dependencies should be exposed as api dependencies.

Example:

    kotlin {
        sourceSets {
            nativeMain {
                dependencies {
                    compileOnly("org.example:lib:1.2.3")
                    // additionally add the compileOnly dependency as an api dependency:
                    api("org.example:lib:1.2.3")
                }
            }
        }
    }

This warning can be suppressed in gradle.properties:

    kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
ForteScarlet commented 4 months ago

Hmmm... I tried it locally and it does have some problems. But it can be solved by another way first: introducing annotation dependencies manually.

kotlin {
    jvm { ... }
    js { ... }
    // ...

    sourceSets.commonMain.dependencies {
        // Adding dependencies proactively
        implementation("love.forte.plugin.suspend-transform:suspend-transform-annotation:2.0.20-Beta1-0.9.1")
    }
}

suspendTransform {
    // Disable here
    includeAnnotation = false
    // ....
}

Default dependencies can also be replaced with constants:

import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.ANNOTATION_GROUP
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.ANNOTATION_NAME
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.ANNOTATION_VERSION

implementation("$ANNOTATION_GROUP:$ANNOTATION_NAME:$ANNOTATION_VERSION")
waltkb commented 4 months ago

I've just tested this out, and can confirm that with:

suspendTransform {
    // ...
    includeAnnotation = false
}

and

implementation("${SuspendTransPluginConstants.ANNOTATION_GROUP}:${SuspendTransPluginConstants.ANNOTATION_NAME}:${SuspendTransPluginConstants.ANNOTATION_VERSION}")

that the build warning disappears. Thanks for your help!