Kotlin Annotation Processor Unit Testing

I have created an annotation processor for kotlin using kapt plugin for gradle. I’m fairly new to kotlin, but I am very familiar with java. When making annotation processors in java, I unit test them using the compile-testing library published by google. After a full day of googling I could not find anything similar to this in the kotlin environment.

Question 1: Does a kapt file generation testing tool already exist that I cannot find?

I spent many more hours trying to create something similar. To do this, I need to embed the kotlin compiler into my project and invoke it from the unit test, based on the advice provided here:
Annotation processor - Unit testing inquiry. I included this jar:

org.jetbrains.kotlin:kotlin-compiler:1.2.51

… in my project and gave it whirl. The only vague source I found showing an example of doing so was on this older post java - How do I run tests compiling a kotlin file in memory and check the result? - Stack Overflow. I figured there might be a way to pass the argument flag to enable annotation processing, but could not get it to compile anything.

Question 2: Is there a more modern way to run kapt during test runtime to validate generated output files?

If there is not a more modern or correct way, then I will need some guidance, documentation, or examples on how to invoke the compiler cli correctly. Here is the invocation class, (almost exactly like that stack overflow post from earlier, and my test:

JvmCompile.kt

object JvmCompile {
    fun exe(input: File, output: Path): Boolean = K2JVMCompiler().run {
        val args = K2JVMCompilerArguments().apply {
            freeArgs = listOf(input.absolutePath)
            loadBuiltInsFromDependencies = true
            destination = output.toAbsolutePath().toString()
            classpath = System.getProperty("java.class.path")
                .split(System.getProperty("path.separator"))
                .filter {
                    val file = File(it)
                    file.exists() && file.canRead()
                }.joinToString(":")
            noStdlib = true
            noReflect = true
            skipRuntimeVersionCheck = true
            reportPerf = true
        }
        execImpl(
            PrintingMessageCollector(
                System.out,
                MessageRenderer.WITHOUT_PATHS, true),
            Services.EMPTY,
            args)
    }.code == 0
}

test fixture

internal class Test {
    @Test
    fun test() {
        val resource = File("src/test/resources/Test.kt")
        val outputPath = Files.createTempDirectory("test")

        JvmCompile.exe(resource, outputPath)

        outputPath.toFile().deleteRecursively()
    }
}

Test.kt

object Test {}

output

"C:\Program Files\Java\jdk1.8.0_121\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50711,suspend=y,server=n -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:C:\Users\wyken\.IntelliJIdea2018.2\system\groovyHotSwap\gragent.jar -javaagent:C:\Users\wyken\.IntelliJIdea2018.2\system\captureAgent\debugger-agent.jar=file:/C:/Users/wyken/AppData/Local/Temp/capture.props -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\plugins\junit\lib\junit-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\plugins\junit\lib\junit5-rt.jar;C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-launcher\1.2.0\junit-platform-launcher-1.2.0.jar;C:\Users\wyken\.m2\repository\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar;C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-engine\1.2.0\junit-platform-engine-1.2.0.jar;C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-commons\1.2.0\junit-platform-commons-1.2.0.jar;C:\Users\wyken\.m2\repository\org\opentest4j\opentest4j\1.1.0\opentest4j-1.1.0.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_121;F:\Documents\Projects\schemata\out\test\classes;F:\Documents\Projects\schemata\out\test\resources;F:\Documents\Projects\schemata\out\production\classes;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.2.51\68faa6fb7e32a7665a6849f242bc621c3ed48101\kotlin-stdlib-jdk8-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\com.squareup\kotlinpoet\0.7.0\6620fe05172f2f8b8e3f81bd4d6edc7dfcb756f0\kotlinpoet-0.7.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-api\5.2.0\9cd901df48d88d8e605a6ccb2c3f140c92db6bf2\junit-jupiter-api-5.2.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler\1.2.51\6cffcdb464cc5453be3f7fda1d7a7e5dccd173d8\kotlin-compiler-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.2.51\a37c0066df119c02f034bf17159089b588ccc41a\kotlin-stdlib-jdk7-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre7\1.2.21\3beb08c67673033183c8652572680587876e64b5\kotlin-stdlib-jre7-1.2.21.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.2.51\36b719a7b84452dd13eeec979d8c82bfb765c57d\kotlin-reflect-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-engine\5.2.0\de87318ccd3dfa1a98ebfef792d362776f1914de\junit-jupiter-engine-5.2.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.2.51\fa8127e505bff50fec291d0dd619d1bda5c619e0\kotlin-stdlib-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-commons\1.2.0\dbce1d822d3dc6c61703b340cd79018518685451\junit-platform-commons-1.2.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.apiguardian\apiguardian-api\1.0.0\3ef5276905e36f4d8055fe3cb0bdcc7503ffc85d\apiguardian-api-1.0.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-runtime\1.2.51\710f0c1c36813aa7df139d6b7ee91ee8738dfdd2\kotlin-runtime-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.opentest4j\opentest4j\1.1.0\c8e2a3e3bc7f3e4bb5075306452db5290f9b117a\opentest4j-1.1.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.2.51\6f8ef6758f396b354e422c3e82d9cd14795fe0e2\kotlin-script-runtime-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.2.51\e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301\kotlin-stdlib-common-1.2.51.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-engine\1.2.0\35fa3529ce843ada1a10b0909ccb4a8148ee638d\junit-platform-engine-1.2.0.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 MetaModelMakerTest,test
Connected to the target VM, address: '127.0.0.1:50711', transport: 'socket'
logging: using Kotlin home directory <no_path>
logging: configuring the compilation environment
warning: classpath entry points to a non-existent location: C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\plugins\junit\lib\junit-rt.jar:C:\Program Files\JetBrains\IntelliJ IDEA 2018.1.5\plugins\junit\lib\junit5-rt.jar:C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-launcher\1.2.0\junit-platform-launcher-1.2.0.jar:C:\Users\wyken\.m2\repository\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar:C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-engine\1.2.0\junit-platform-engine-1.2.0.jar:C:\Users\wyken\.m2\repository\org\junit\platform\junit-platform-commons\1.2.0\junit-platform-commons-1.2.0.jar:C:\Users\wyken\.m2\repository\org\opentest4j\opentest4j\1.1.0\opentest4j-1.1.0.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar:C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar:C:\Program Files\Java\jdk1.8.0_121:F:\Documents\Projects\schemata\out\test\classes:F:\Documents\Projects\schemata\out\test\resources:F:\Documents\Projects\schemata\out\production\classes:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.2.51\68faa6fb7e32a7665a6849f242bc621c3ed48101\kotlin-stdlib-jdk8-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\com.squareup\kotlinpoet\0.7.0\6620fe05172f2f8b8e3f81bd4d6edc7dfcb756f0\kotlinpoet-0.7.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-api\5.2.0\9cd901df48d88d8e605a6ccb2c3f140c92db6bf2\junit-jupiter-api-5.2.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler\1.2.51\6cffcdb464cc5453be3f7fda1d7a7e5dccd173d8\kotlin-compiler-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.2.51\a37c0066df119c02f034bf17159089b588ccc41a\kotlin-stdlib-jdk7-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jre7\1.2.21\3beb08c67673033183c8652572680587876e64b5\kotlin-stdlib-jre7-1.2.21.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.2.51\36b719a7b84452dd13eeec979d8c82bfb765c57d\kotlin-reflect-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-engine\5.2.0\de87318ccd3dfa1a98ebfef792d362776f1914de\junit-jupiter-engine-5.2.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.2.51\fa8127e505bff50fec291d0dd619d1bda5c619e0\kotlin-stdlib-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-commons\1.2.0\dbce1d822d3dc6c61703b340cd79018518685451\junit-platform-commons-1.2.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.apiguardian\apiguardian-api\1.0.0\3ef5276905e36f4d8055fe3cb0bdcc7503ffc85d\apiguardian-api-1.0.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-runtime\1.2.51\710f0c1c36813aa7df139d6b7ee91ee8738dfdd2\kotlin-runtime-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.opentest4j\opentest4j\1.1.0\c8e2a3e3bc7f3e4bb5075306452db5290f9b117a\opentest4j-1.1.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.2.51\6f8ef6758f396b354e422c3e82d9cd14795fe0e2\kotlin-script-runtime-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.2.51\e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301\kotlin-stdlib-common-1.2.51.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar:C:\Users\wyken\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-engine\1.2.0\35fa3529ce843ada1a10b0909ccb4a8148ee638d\junit-platform-engine-1.2.0.jar:C:\Users\wyken\.IntelliJIdea2018.2\system\groovyHotSwap\gragent.jar:C:\Users\wyken\.IntelliJIdea2018.2\system\captureAgent\debugger-agent.jar
exception: java.lang.AssertionError: Built-in class kotlin.Any is not found
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getBuiltInClassByName(KotlinBuiltIns.java:440)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.access$700(KotlinBuiltIns.java:57)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns$4.invoke(KotlinBuiltIns.java:141)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns$4.invoke(KotlinBuiltIns.java:138)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:448)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:523)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getBuiltInClassByName(KotlinBuiltIns.java:433)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getBuiltInClassByName(KotlinBuiltIns.java:475)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getAny(KotlinBuiltIns.java:485)
	at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getAnyType(KotlinBuiltIns.java:715)
	at org.jetbrains.kotlin.resolve.DescriptorResolver.getDefaultSupertype(DescriptorResolver.java:186)
	at org.jetbrains.kotlin.resolve.DescriptorResolver.resolveSupertypes(DescriptorResolver.java:156)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.computeSupertypes(LazyClassDescriptor.java:699)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor$LazyClassTypeConstructor.computeSupertypes(LazyClassDescriptor.java:602)
	at org.jetbrains.kotlin.types.AbstractTypeConstructor$supertypes$1.invoke(AbstractTypeConstructor.kt:34)
	at org.jetbrains.kotlin.types.AbstractTypeConstructor$supertypes$1.invoke(AbstractTypeConstructor.kt:22)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:354)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:410)
	at org.jetbrains.kotlin.types.AbstractTypeConstructor.getSupertypes(AbstractTypeConstructor.kt:23)
	at org.jetbrains.kotlin.types.AbstractTypeConstructor.getSupertypes(AbstractTypeConstructor.kt:22)
	at org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getSuperClassNotAny(DescriptorUtils.kt:139)
	at org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getAllSuperclassesWithoutAny(DescriptorUtils.kt:351)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$inheritanceScopeWithoutMe$1.invoke(ClassResolutionScopesSupport.kt:52)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$inheritanceScopeWithoutMe$1.invoke(ClassResolutionScopesSupport.kt:31)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:354)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:410)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$inheritanceScopeWithMe$1.invoke(ClassResolutionScopesSupport.kt:58)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$inheritanceScopeWithMe$1.invoke(ClassResolutionScopesSupport.kt:31)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:354)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:410)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$scopeForMemberDeclarationResolution$1.invoke(ClassResolutionScopesSupport.kt:67)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport$scopeForMemberDeclarationResolution$1.invoke(ClassResolutionScopesSupport.kt:31)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:354)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:410)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.getScopeForMemberDeclarationResolution(LazyClassDescriptor.java:345)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getScopeForMemberDeclarationResolution(LazyClassMemberScope.kt:135)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.doGetFunctions(AbstractLazyMemberScope.kt:102)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.access$doGetFunctions(AbstractLazyMemberScope.kt:39)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope$functionDescriptors$1.invoke(AbstractLazyMemberScope.kt:51)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope$functionDescriptors$1.invoke(AbstractLazyMemberScope.kt:39)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:448)
	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:523)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.getContributedFunctions(AbstractLazyMemberScope.kt:91)
	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getContributedFunctions(LazyClassMemberScope.kt:189)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitNamedFunction(LazyDeclarationResolver.kt:125)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitNamedFunction(LazyDeclarationResolver.kt:94)
	at org.jetbrains.kotlin.psi.KtNamedFunction.accept(KtNamedFunction.java:48)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:94)
	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:91)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.createFunctionDescriptors(LazyTopDownAnalyzer.kt:283)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:204)
	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations$default(LazyTopDownAnalyzer.kt:60)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:113)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:85)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:370)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:61)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:101)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:361)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.kt:343)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources(KotlinToJVMBytecodeCompiler.kt:242)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:200)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:95)
	at JvmCompile.exe(JvmCompile.kt:26)
	at MetaModelMakerTest.test(MetaModelMakerTest.kt:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:513)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
	at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:113)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Disconnected from the target VM, address: '127.0.0.1:50711', transport: 'socket'

Process finished with exit code 0

any help is appreciated.

I have the same error. I do not know how to fix this problem. Can anybody help?

O, i solved. Something like this:

fun systemClasspath(): List<File> {
  val list: MutableList<File> = System.getProperty("java.class.path")
    .split(System.getProperty("path.separator"))
    .map { File(it) }
    .filter { it.exists() && it.canRead() }
    .toMutableList()

  // start spike-nail
  val dir = File("/path/to/apache-tomcat-9.0.13/webapps/ROOT/WEB-INF/lib")

  dir.listFiles().forEach {
    list.add(it)
  }
  // finish spike-nail
  
  return list.toList()
}

fun classpath(): String {  // <---- this classpath is used for compiler
  return systemClasspath().joinToString(System.getProperty("path.separator")) { it.absolutePath }
}

BUT this solution is not good. :frowning: A big spike-nail!!!

Does anybody know a solution without spike-nail?

From what I understand you are missing a reference to the kotlin standard library when calling execImpl. I guess there is a version of it in your tomcat lib folder and that’s why your version works. It should probably be enough to just add the standard library to the classpath. Otherwise you could probably also set noStdlib to false.

i think so, but setting noStdlib to false (default value) gives the same error.

i have standard library in classpath:

  compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.21"

In case anyone is still having a similar issue, I have created a library for compile-testing Kotlin code that may be of interest to you: GitHub - tschuchortdev/kotlin-compile-testing: A library for testing Kotlin and Java annotation processors, compiler plugins and code generation