This message was deleted.
# community-support
s
This message was deleted.
s
Use
getRepositoryId
from Gradle 8.2 on.
e
Where do I look up the repository from that id?
s
That id is the name that was previously returned by
getRepositoryName
. They just introduced a different function for basically the same thing in order to be able to change its semantics, I guess.
e
In previous versions
getRepositoryName
was returning the name of the repository (e.g. Google, MavenRepo, etc...). Now
getRepositoryId
returns something like
26c913274550a0b2221f47a0fe2d2358
s
Really? I was pretty sure to have tested for that... apologies then, I need to double-check my code.
e
It looks like
getRepositoryName
now returns the same value as
getRepositoryId
(e.g.
26c913274550a0b2221f47a0fe2d2358
)
s
I'm using whatever these functions return as a key into a map that associates
project.repositories.name
with
UrlArtifactRepository
. That still seems to work.
e
I'm doing the same 🤔
Here's how I'm mapping them where the name is the actual name given to the repository:
Copy code
private Map<String, ArtifactRepository> getAllRepositories(Project project) {
    Map<String, ArtifactRepository> projectRepositories = project.getRepositories().getAsMap();

    // nasty cast because of <https://github.com/gradle/gradle/issues/17295>
    Map<String, ArtifactRepository> settingsRepositories =
        ((GradleInternal) project.getGradle())
            .getSettings()
            .getDependencyResolutionManagement()
            .getRepositories()
            .getAsMap();

    settingsRepositories.putAll(projectRepositories);
    return settingsRepositories;
  }
And then using
getRepositoryName
(and now
getRepositoryId
) as a key into that map, but it returns the hex string id:
Copy code
((ResolvedComponentResultInternal) resolvedComponentResult).getRepositoryName();
s
What does
getAsMap()
do exactly? I.e., how does it know what's supposed to be the key, and what the value? In Kotlin, I'm doing the association explicitly, see https://github.com/oss-review-toolkit/ort/blob/6e68575eefb693307170d9b7af978260fa1[…]ckage-managers/gradle-plugin/src/main/kotlin/OrtModelBuilder.kt
e
getAsMap
is a function on
NamedDomainObjectCollection
that returns a map of associated names to values.
Building the map myself manually yields the same results
s
And for me, using
getAsMap
also works to make the lookup work...
Maybe there's something different for your settings repos?
e
Are you using maven repositories? Looking through the source it doesn't look like
name
gets exposed for maven repos anymore.
s
Yes, actually exclusively Maven repos...
e
MavenRepositoryDescriptor is created using the repo name and a hashed id both of which are exposed in RepositoryDescriptor. However DefaultResolvedComponentResult getRepositoryName and getRepositoryId both use the hashed id which is sent to it via a ResolvedGraphComponent I'm still looking to see how those get linked together to see why I might be getting the hashed id while you get the repo name.
The connection is happening in ResolveIvyFactory with the created resolver (which becomes
delegate
in the CachingModuleComponentRegistry that is used to supply the repository id for the
ResolvedGraphComponent
) getting the MavenRepositoryDescriptor that contains the repository name and hashed id. However the repository name doesn't get used anywhere as far as I can tell. Is the project that is applying your plugin using Gradle 8.2?
@Louis Jacomet looks like this is related to a commit that you reverted - https://github.com/gradle/gradle/pull/25457 I know that
ResolvedComponentResultInternal.getRepositoryName
is deprecated and the doc says not to use it, but it is the only way to get that information as far as I can tell. This behavior change was not documented in the release notes for Grade 8.2. Any idea on when this will be supported again?