Resolve project from other build (composite) - ForeignBuildIdentifier

Hey guys. I am trying to copy the sources jar from references project dependencies. This works ok for projects from the current build:

  tasks.findByPath("sourcesJar")?.also { sourcesJarTask ->
      .forEach {
        return it;

But how can I do this for projects from composite builds? All I get from my artifact resolution query is a ForeignBuildIdentifier. But how can I get a hold to the projects from the other build?

More code to (maybe) understand better, what I am doing:

      val incoming = configurations.runtimeClasspath.get().incoming

      val componentIds = {
        val resolved = it as ResolvedDependencyResult
        val selectedId =

      val result = dependencies.createArtifactResolutionQuery()
        .withArtifacts(JvmLibrary::class, SourcesArtifact::class)

      result.components.forEach {
        if (it is UnresolvedComponentResult) {
          val projectId = as ProjectComponentIdentifier

          if (! {
                 //What do to do here?