JavaExec - classpath from plugin?

I’m trying to create a task in a kotlin plugin that extends JavaExec. The main class is inside of my plugin. I can configure everything just fine except for the classpath - I need to add my plugin jar to the classpath of the the task I’m guessing for it to pick up on my main class, here’s my task creation:

    project.tasks.create("startApp", { = "myapp"
        it.main =
        val configString = Gson().toJson(config)
        it.args = listOf(configString)

Any thoughts on how set the classpath would be appreciated. I suppose I could always break the main class out into a separate module, and add it to the project dependencies via the plugin, then resolve the jar, but I’d like to avoid that if at all possible.

I went with creating a library with the main class, and setting the classpath from a configuration. It works, but it would still be nice to avoid it if possible.

You should be setting the classpath from a configuration, but there’s nothing forcing you to break out your main class into a separate library. That configuration can depend on your main plugin JAR same as it can depend on the separate module. You could also just reference the buildscript classpath configuration that already contains your plugin if it’s been applied.

@jjustinic - thanks, I didn’t realize I could get project.buildScript.configurations, that’s very helpful, and I got it working all from one package. But it only works if I use the old buildscript { dependencies { classpath … } } way of loading a plugin, and not if I use the newer plugins {} style.

Is there any way to get a configuration that includes my plugin when it’s applied via plugins {}?

I used to give me a generated BuildConfig class with the version number in it that I can access, so I can use that to create my configuration containing just my plugin and dependencies. :wink: works good.