Call `javaexec` from custom task declared inside buildSrc

Hi,

I’ve written a custom task in Kotlin and located it inside buildSrc as recommended. The custom task calls javaexec. Something like this:

    private fun custom() {
        project.javaexec {
            main = "com.thirdParty.something.Main"
            classpath = ???
            args("...")
        }
    }

Some questions:

  1. Is project.javaexec the best way to call a main method from within a custom task?
  2. How can I configure classpath such that com.thirdParty.something.Main remains a dependency of the custom task (i.e. buildSrc/build.kotlin.kts), and not the main project?

Thanks!