How to Test Kotlin Code in Quarantine?

Hello all!

With the current quarantine, and end of my Kotlin projects approaching, I am looking to test this code, similarly to how I would test it on a robot. I use IntelliJ, although I do have VSCode and recognize what commands they have to offer, even though I use Kotlin.

My code is building properly, so I am looking for a way to do a more in-depth “test”. I understand that WPILib offers the desktop simulation, but does this work for Kotlin?

Every time I try this command in VSCode, I receive the following.

ConfigError: Main class 'frc.robot.Main' doesn't exist in the workspace.

This confuses me greatly as it is indeed present, and I have viewed several other Kotlin examples. Again, is it merely because I run Kotlin instead of Java in this instance?

My github can be found here.

Thank you in advance!

If you look at the example build.gradle here, you can see that it actually uses MainKt instead of Main.

So all you should have to do is change it to frc.robot.MainKt in your build.gradle.

Now, if you wanted to, you could add the @file:JvmName("Main") annotation above your package declaration and it would be put in the class Main instead of MainKt. You can read more about that here:

1 Like

Unfortunately, that did not appear to fix my problem. Now it reads,

ConfigError: Main class 'frc.team2539.robot.MainKt' doesn't exist in the workspace

Any more ideas?

Can you push to your GitHub real quick?

You are sure there your main file is ‘frc.team2539.robot.Main’ right without the annotation? Also, with my above response, you should only do one or the other. If you put the @file:JvmName("Main") on it, then you don’t have to call it MainKt. If you don’t put that annotation on it then you have to call it MainKt.

Sorry my response might have been a little confusing. I just wanted to give you some options.

Of course. Thank you again! Here is the link

I have also been adding the ‘team2539’ directory, so I incorporated that as well.

I also commented out several lines in Main.kt, as shown in the kotlin example you referenced.

So I cloned your repository and I was able to run it successfully. Can I suggest you try running the command ./gradlew clean simulateJava or gradlew.bat clean simulateJava on windows command prompt.

Also next time you get a stacktrace, can you provide the entire stacktrace and the command you ran. More information may not always be useful, but sometimes it is.

Right, so that works for me too.

The error did not originate from me cleaning or building, it occurs when I run the VSCode command, WPILib: Simulate Robot Code on Desktop.

This is what gave me the previous error, and with no significant traceback whatsoever. What I was asking was is this even possible, and if so why am I receiving the error?

@Thad_House is this something you can help with? I don’t normally mess with VS Code so I can’t help much here. Is this caused by not using the user’s gradle configuration and the VS Code simulation stuff overriding something?

This should be possible. I’m not really sure why the command line works but doing it in VS Code doesn’t.

Which project are you attempting to simulate in VS Code? You have 3 in that repo, so just want to make sure the right one is being tested.

Also, VS Code doesn’t support Kotlin debugging (not us, just there is no Kotlin language support or extension), so you won’t actually gain anything there over just running ./gradlew simulateJava

I believe he’s using the “Kobot” one since that’s most recently updated.

Kobot, is the one I’m running, yes.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.