I have a plugin project that depends on
org.jetbrains.kotlin.multiplatform
and also on
embeddedKotlin("compiler-embeddable")
.
The reason is, that one of the plugins applies
kotlin("multiplatform")
and another is using
val File.importedFiles: List<File>
get() = if (!isFile) {
emptyList()
} else {
PsiManager
.getInstance(
KotlinCoreEnvironment
.createForProduction(
Disposer.newDisposable(),
CompilerConfiguration().apply {
put(MESSAGE_COLLECTOR_KEY, NONE)
},
JVM_CONFIG_FILES
)
.project
)
.findFile(CoreLocalVirtualFile(CoreLocalFileSystem(), toPath()))
.let { it as KtFile }
.fileAnnotationList
?.annotationEntries
?.asSequence()
?.filter { it.shortName?.asString() == "Import" }
?.flatMap { it.valueArgumentList?.arguments ?: emptyList() }
?.mapNotNull { it.getArgumentExpression() as? KtStringTemplateExpression }
?.map { it.entries.first() }
?.mapNotNull { it as? KtLiteralStringTemplateEntry }
?.map { resolveSibling(it.text) }
?.flatMap { it.importedFiles + it }
?.toList()
?: emptyList()
}
to get the files a given
*.main.kts
file imports.
That latter cannot be done as a worker action because this is needed at configuration time to determine the input files for a task that is executing that
*.main.kts
file.
But now when I update the Kotlin version to 2.1.0 I get a warning
> w: The artifact
org.jetbrains.kotlin:kotlin-compiler-embeddable
is present in the build classpath along Kotlin Gradle plugin.
> This may lead to unpredictable and inconsistent behavior.
> For more details, see:
https://kotl.in/gradle/internal-compiler-symbols
when applying that plugin.
As it is a runtime issue, I assume that splitting into multiple plugins would also not help as in the end it would again be in the same runtime classpath.
How would I solve this task in a forward-compatible way, besides putting the logic into a separate Kotlin file or script and executing it as external process instead of in-process, or splitting it into multiple plugins and ensuring those plugins are not applied to the same projects, or relocating the compiler classes into my plugin?