# Gradle 8.9 how to convert buildScript to new style

**URL:** <https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099>\
**Category:** Help/Discuss\
**Created:** [August 11, 2024, 6:58pm UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099 "2024-08-11T18:58:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArvinB](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ArvinB](https://discuss.gradle.org/u/ArvinB)\
**Post date:** [August 11, 2024, 6:58pm UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/1 "2024-08-11T18:58:13Z")

</div>

Hi there, first time posting, long time reading and using gradle… 🙂

I have the following in my `settings.gradle` file. I would like to convert this to use the new style of pluginmanagement { … } with `includeBuild`. Is there a better way of writing this so that in my `build.gradle` I can add my gradle plugin into the plugins section?

```gradle
buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://<artifactory_url>/artifactory/<artifactory_repo>'
            credentials {
                username = System.getenv("user_artifactory_repo") ?: "${user_artifactory_repo}"
                password = System.getenv("pass_artifactory_repo") ?: "${pass_artifactory_repo}"
            }
        }
    }
    dependencies { classpath '<maven-group>:<artifact-id>:latest.release' }
}

```

---

<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:** [August 11, 2024, 11:16pm UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/2 "2024-08-11T23:16:30Z")

</div>

Just move your repository to the `pluginManagement { respositories { ... } }` section?

I also highly recommend to switch to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

---

<div class="post-metadata">

**Author:** ![ArvinB](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ArvinB](https://discuss.gradle.org/u/ArvinB)\
**Post date:** [August 12, 2024, 3:03am UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/3 "2024-08-12T03:03:53Z")

</div>

Thank you for the response. I should have mentioned that the artifact is a custom gradle plugin. Since it is not signed, then this is not published into mavenCentral(). So I think I’m stuck using the buildscript to define the custom repository and dependency → classpath before the `plugins { ... }` block is called. Would this be accurate or is there some new trick I’m not aware of?

---

<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:** [August 12, 2024, 9:37am UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/4 "2024-08-12T09:37:15Z")

</div>

> Thank you for the response. I should have mentioned that the artifact is a custom gradle plugin.

Yes, I got that right from the start, doesn’t change my response.

> Since it is not signed, then this is not published into `mavenCentral()`.

Well, you can just do so and publish to Maven Central if you want the plugin publicly available.  
Or even better publish it to Gradle Plugin Portal, then it is also integrated in the Plugin Portal web UI.  
If it should not be publicly available, just keep publishing it to your internal repository.  
But still doesn’t change anything with my initial response.

> So I think I’m stuck using the buildscript to define the custom repository and dependency → classpath before the plugins { … } block is called. Would this be accurate or is there some new trick I’m not aware of?

No, it is not accurate and no, no new trick necessary.  
As I said, just define your repository as plugin repository.

---

<div class="post-metadata">

**Author:** ![ArvinB](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ArvinB](https://discuss.gradle.org/u/ArvinB)\
**Post date:** [August 12, 2024, 12:15pm UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/5 "2024-08-12T12:15:09Z")

</div>

Got it!

So when I did that, how do you define the `dependencies` so that in `build.gradle` I could define:

```groovy
plugins {
   id 'my-plugin'
}

```

I kept getting an error saying it couldn’t find the plugin in the repository.

---

<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:** [August 12, 2024, 12:46pm UTC](https://discuss.gradle.org/t/gradle-8-9-how-to-convert-buildscript-to-new-style/49099/6 "2024-08-12T12:46:52Z")

</div>

Did you publish the [Plugin Marker Artifacts](https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers)?  
If not, you should, if you did, you probably miss to configure the version somewhere.

Besides that, if your plugin ID really looks like that, you should change it anyway, plugin IDs without namespace (without `.`) should not be used but be reserved for built-in plugins to not risk name clashes.

If you do not publish the marker artifact and don’t want to (you really should though) you can use `pluginManagement { resolutionStrategy { ... } }` to do the mapping from ID to code artifact manually for which the marker artifact would have been used otherwise.
