Jakub Chrzanowski
04/02/2024, 8:09 AM@RequiresOptIn(message = "This API belongs to ${Plugins.RUN}")
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class IntelliJPlatformRun
And a task:
@IntelliJPlatformRun
abstract class RunIdeTask : JavaExec() {}
Which is registered within my plugin:
@OptIn(IntelliJPlatformRun::class)
abstract class IntelliJPlatformPlugin : Plugin<Project> {
override fun apply(project: Project) {
// register RunIdeTask
}
}
In the build.gradle.kts
I apply this plugin with:
plugins {
id("org.jetbrains.intellij.platform") version "..."
}
and the runIde
task is present, but when trying to reconfigure it with:
tasks {
runIde {
splitMode = false
}
}
I get [OPT_IN_USAGE_ERROR] This API belongs to org. jetbrains. intellij. platform. run
unless I explicitly @OptIn
again in the client’s code.
I’m looking for a contract to let me use such classes without effort when I apply the plugin that already has relevant opt-ins.Vampire
04/02/2024, 8:51 AM@OptIn
, so when anything in the plugin is used, the opt-in requirement does not propagate, except if the consumer uses an API that has a class that requires opt-in in its signature.
But with the last snippet you showed, you directly use an opt-in requiring type / method and so need to explicitly opt-in in that code.
It might be not a proper use-case for opt-in requiring if you want the consumer to use the type.
If for whatever reason you want to prevent others to add new tasks of that type, you probably need to instead make the constructor internal
and instantiate the task class manually, but then you also loose the decorations Gradle would add.Jakub Chrzanowski
04/02/2024, 9:15 PMJakub Chrzanowski
04/02/2024, 9:16 PM