# How to run shell commands in init.gradle.kts with gradle 8.13?

**URL:** <https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930>\
**Category:** Help/Discuss\
**Created:** [April 30, 2025, 5:02pm UTC](https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930 "2025-04-30T17:02:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![omerk706](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@omerk706](https://discuss.gradle.org/u/omerk706)\
**Post date:** [April 30, 2025, 5:02pm UTC](https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930/1 "2025-04-30T17:02:50Z")

</div>

In my init.gradle.kts, I have this block:

```gradle
initscript {
    fun fetchCodeArtifactToken(): String {
        val output = java.io.ByteArrayOutputStream()

         exec {
            commandLine(
                "aws", "codeartifact", "get-authorization-token",

```

Our conventions plugins are in codeartifact, so without this access nothing works.  
`exec` is now deprecated, and the only alternative I can find documentation for involves a task, which I can’t rely on, since the `project` object does not exist during this script execution.

What is the correct way to define this function or just to run the shell command in this timing?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [April 30, 2025, 6:33pm UTC](https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930/2 "2025-04-30T18:33:34Z")

</div>

Hm, when deprecating this in `InitScriptApi` they maybe did this accidentally, especially as the deprecation note only contains stuff usable at other places but not in an init script.

I recommend you create an issue over at GitHub so that they can consider reverting this deprecation as there is no proper replacement.

In the meantime, the work-around would probably be to use normal Kotlin means to call external process, so `ProcessBuilder` for example or whatever the Kotlin substitute is, if there is one.

---

<div class="post-metadata">

**Author:** ![omerk706](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@omerk706](https://discuss.gradle.org/u/omerk706)\
**Post date:** [May 2, 2025, 8:47pm UTC](https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930/3 "2025-05-02T20:47:28Z")

</div>

Thanks,  
ProcessBuilder solved it for me.

This should probably be documented as an alternative for when tasks are not available yet, but the point is there is a working solution that does not indicate deprecation.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 3, 2025, 12:52am UTC](https://discuss.gradle.org/t/how-to-run-shell-commands-in-init-gradle-kts-with-gradle-8-13/50930/4 "2025-05-03T00:52:27Z")

</div>

The point is, that this would imho not be deprecated at this spot and that you should report to Gradle folks, as there is no Gradle alternative there.
