Version Catalogs and init scripts

I am having trouble accessing a predefined version catalog in an init script. I have something like this

//init.gradle.kts

initscript {
    repositories {
        gradlePluginPortal()
    }
}

settingsEvaluated {
    dependencyResolutionManagement {
        repositories {
            mavenCentral()
        }
        versionCatalogs {
             create("tpl") {
                  library("junit-bom", "org.junit:junit-bom:5.11.2")
             }
        }
    }
}

allprojects {
     val catalogs = extensions.getByType<VersionCatalogsExtension>()

     tasks.register("some-task") {
          doLast {
              println("this is a test")
          }
     }
}

When I try to run some-task using the init-script, I keep getting the error

Extension of type 'VersionCatalogsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension]

Any idea why am I getting this error and what can I do resolve this?

Seems when that allprojects content is evaluated the extension is not yet registered.
I think it basically is the same issue as Register `VersionCatalogsExtension` before `beforeProject` lifecycle hooks · Issue #31289 · gradle/gradle · GitHub and you should add your use-case there.

Thanks for pointing out this existing issue. I’ll add this use case there.