Is there an API to check/read from a build script ...
# community-support
m
Is there an API to check/read from a build script the repos defined in the dependencyResolutionManagement section of the settings script?
v
What is the use-case?
I don't think there is any supported API to retrieve those, you cannot even get to the settings object from the build script afair.
m
E.g., a build script convention plugin, where we want to define project repos, but only if they are not already defined in the dependencyResolutionManagement, which in turn could be done in an init script. I suppose the workaround could be for the init script to set a project property saying "I've set the dependencyResolutionManagement repos", and for the build script convention plugin to use that, instead of attempting to read the repos.
v
You cannot set a project property from inside Gradle. You can set an extra property and depending on how you retrieve a project property it will eventually be treated like a project property. But everytime you use extra properties you should feel dirty according to Gradle folks as it is practically always a work-around for not doing something properly. To transport information it would be better to either register an extension that provides the information or using a shared build service that holds the information. But actually what you describe sounds pretty fragile. For example if a user has a personal init script that always adds
mavenLocal()
to those repositories (even though noone should ever use
mavenLocal()
at all optimally), then the build suddenly breaks for that user as no repository provides the needed dependencies. You could for example also set the repositories mode to
PREFER_SETTINGS
so that repositories declared on a project are ignored and the settings ones are used. Then you do not need to decide whether to add the repositories from the convention plugin or not but can always add them. Or you just settle on one way to do it so that no flexibility is necessary. 🤷‍♂️
👍 1