Gradle configuration cache - resolvedArtifacts migration, how to get group / name

Hi,

trying to make my code CC compatible, I stumbled over the following problem / question.

With the “old” API I could do the following:

doFirst {
    testPlugins
        .resolvedConfiguration
        .resolvedArtifacts
        .filter { it.extension == "hpi" || it.extension == "jpi" }
        .forEach {
            pluginsMapping[it.file.name] = JenkinsPlugin(it.name, it.extension)
        }
}

The testPlugins configuration has module dependency and also a local subproject one. In the code above this is all abstracted and I can get e.g. name or group of the artifact, see [0].

I tried to use the incoming view on that to use [1] and rewrote it like that:

    val artifacts: Provider<Set<ResolvedArtifactResult>> =
        testPlugins
            .incoming
            .artifacts
            .resolvedArtifacts

    doFirst {
        artifacts
            .get()
            .filter { it.file.extension == "hpi" || it.file.extension == "jpi" }
            .forEach {
                val pluginName =
                    when (val compId = it.variant.owner) {
                        is ModuleComponentIdentifier -> {
                            compId.moduleIdentifier.name
                        }

                        is DefaultProjectComponentIdentifier -> {
                            compId.projectName
                        }

                        else -> {
                            throw GradleException("$compId unknown!")
                        }
                    }
                Logging.getLogger("plugin").debug("Build-Mapping: {} with filename: {}", pluginName, it.file.name)
                JenkinsHelper.pluginsMapping[it.file.name] = JenkinsPlugin(pluginName, it.file.extension)

The result list does not have anymore in the forEach body a name + group I can use, but I have to make a difference between modules and local projects.

For my example I used the “hack” that I know my projectName is the same like the module name of my subproject, but how would I e.g. access the group in the DefaultProjectComponentIdentifier case, I am looking for something like:

is DefaultProjectComponentIdentifier -> {
  compId.moduleInfo.name
}

My best guess is, I miss some API / doc link how I can access those information - anyone can help me with that?

[0] ResolvedArtifact (Gradle API 9.5.0)

[1] ResolvedArtifactResult (Gradle API 9.5.0)

Afair, you cannot get the coordinates from the direct view.
Instead you need additionally the resolved dependency tree and use both to get the information you want afair.

But if all you want is external dependency or project dependency, just use two artifact views, you can filter them to only contain project dependencies or only others easily by using componentFilter on the artifact view.

Hm, actually lets take a step back - I just want to find a solution for the “old” code:

doFirst {
    testPlugins
        .resolvedConfiguration
        .resolvedArtifacts
        .filter { it.extension == "hpi" || it.extension == "jpi" }
        .forEach {
            pluginsMapping[it.file.name] = JenkinsPlugin(it.name, it.extension)
        }
}

My “new” solution was just a try to get his converted but I actually don’t know how to do that best and did not find a docs example how to migrate, hence why I am asking for advice.

As I said.
You probably need to get both and combine them.
I cannot give an example, I’m on vacation.
But I think I have an example somewhere here or on the community Slack that needed something similar.