Use of versionCatalogs in settings plugin

Hello there

I am currently using a script file to setup my dependencyResolutionManagement in mulitple projects. I would like to change this to a plugin, but I am having some issues using my TOML file the same way in the plugin as I do in the script file.

I load my libs.version.toml file as such.

dependencyResolutionManagement {
      versionCatalogs {
        create("libs") {
          from(files("libs.versions.toml"))
        }
    }
}

And apply it where needed with

apply(from = "$gradleFolder/dependencyResolutionManagement.gradle.kts")

But it seems that I do not have the same apis when running from a plugin, which I think is odd, since it to my understanding would run in the same context.

I denfine it as such in my plugin.

  override fun apply(settings: Settings) {
    settings.dependencyResolutionManagement {
      versionCatalogs {
        create("libs") {
          from(files("libs.versions.toml"))
        }
      }
    }
  }

But files() is not available here. I trace it back to a part of the project, which ofcourse isn’t created yet at this time (don’t understand how it is different as a script file).

If I remove the files() wrapper I get a IllegalDependencyNotation exception.

What is the correct way of doing this as plugin?

Thank you in advance!

From the top of my head, what you need is settings.layout.settingsDirectory.files("libs.versions.toml")

That did it. Thank you very much!

1 Like