Maven-publish publishing repository in init.gradle?

Init scripts do not execute against a Project in the same way that a build script does, instead it delegates to a Gradle instance.

https://docs.gradle.org/current/userguide/init_scripts.html

Try wrapping your code with allprojects:

allprojects {
    // your code
}