# Call \`javaexec\` from custom task declared inside buildSrc

**URL:** https://discuss.gradle.org/t/call-javaexec-from-custom-task-declared-inside-buildsrc/34681
**Category:** Help/Discuss
**Created:** [January 25, 2020, 1:45pm UTC](https://discuss.gradle.org/t/call-javaexec-from-custom-task-declared-inside-buildsrc/34681 "2020-01-25T13:45:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![egmanoj](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@egmanoj](https://discuss.gradle.org/u/egmanoj)
#### Post date: [January 25, 2020, 1:45pm UTC](https://discuss.gradle.org/t/call-javaexec-from-custom-task-declared-inside-buildsrc/34681/1 "2020-01-25T13:45:12Z")

</div>

Hi,

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

```gradle
    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!
