# Declare and use project.extmyFunction in Kotlin

**URL:** <https://discuss.gradle.org/t/declare-and-use-project-extmyfunction-in-kotlin/37671>\
**Category:** Help/Discuss\
**Created:** [September 21, 2020, 9:52am UTC](https://discuss.gradle.org/t/declare-and-use-project-extmyfunction-in-kotlin/37671 "2020-09-21T09:52:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [September 21, 2020, 9:52am UTC](https://discuss.gradle.org/t/declare-and-use-project-extmyfunction-in-kotlin/37671/1 "2020-09-21T09:52:31Z")

</div>

I’m rewiring my plugin from groovy to Kotlin.  
I’m often using this code in Groovy

```
    project.ext.isSnapshotBuild = {
        return versionProvider.get().isSnapshotBuild()
    }

    project.ext.isWindows = {
        return Os.isFamily(Os.FAMILY_WINDOWS)
    }

    project.ext.isIDEBuild = {
        return (boolean) project.properties['android.injected.invoked.from.ide']
    }

```

How rewrite the same logic to Kolin. I need to keep compatibility with project which still using groovy based build script.

And what is currently the suggested way how to do it?  
I was thinking about project.extensions.create where I can put my object with my methods which can be called easily from Kotlin build script. It is a good way?

I did not found a way how to extend Project class in the way that will be available in the project which using my plugin. Inside of plugin I have this

```
fun Project.isIDEBuild(): Boolean {
    return this.hasProperty("android.injected.invoked.from.ide")
}

```

but it is not working the project which using my plugin.

---

<div class="post-metadata">

**Author:** ![Tomas\_Prochazka](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/tomas_prochazka/32/261_2.png) [@Tomas\_Prochazka](https://discuss.gradle.org/u/Tomas_Prochazka)\
**Post date:** [September 29, 2020, 7:11pm UTC](https://discuss.gradle.org/t/declare-and-use-project-extmyfunction-in-kotlin/37671/2 "2020-09-29T19:11:52Z")

</div>

So, this is a correct way how to do it in a way compatible with Groovy build scripts

```
project.extra["isIDEBuild"] = KotlinClosure0({
    project.isIDEBuild
})

```

For Kotlin based build script is the best way to user Kotlin extension function or property like

```
val Project.isIDEBuild: Boolean
    get() {
        return this.hasProperty("android.injected.invoked.from.ide")
    }
```
