Skip to content

Add runtime provider for plugin-annotations #22

@kyay10

Description

@kyay10

Otherwise, testData files might reference functions from the annotation lib, but then fail at runtime during testing.

Here's how I've done it (I'll open a PR soon enough):

import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator
import org.jetbrains.kotlin.test.services.RuntimeClasspathProvider
import org.jetbrains.kotlin.test.services.TestServices
import java.io.File

class PluginAnnotationsProvider(testServices: TestServices) : EnvironmentConfigurator(testServices) {
  companion object {
    val annotationsRuntimeClasspath =
      System.getProperty("annotationsRuntime.classpath")?.split(File.pathSeparator)?.map(::File)
        ?: error("Unable to get a valid classpath from 'annotationsRuntime.classpath' property")
  }

  override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
    configuration.addJvmClasspathRoots(annotationsRuntimeClasspath)
  }
}

class PluginRuntimeAnnotationsProvider(testServices: TestServices) : RuntimeClasspathProvider(testServices) {
  override fun runtimeClassPaths(module: TestModule) = PluginAnnotationsProvider.annotationsRuntimeClasspath
}

then in AbstractJvmBoxTest.configure, I added:

useCustomRuntimeClasspathProviders(::PluginRuntimeAnnotationsProvider)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopen to contributionsContributions from the community are welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions