Hi Everyone, long shot as I realize this is probably not the right channel but does anyone know how ...
j
Hi Everyone, long shot as I realize this is probably not the right channel but does anyone know how to copy the artifacts in a gradle
configuration
into another project when that configuration is exposed? I have set up a producer configuration and I am consuming it in a project as shown in the docs but there are multiple producers to a single consumer and the copy task resolves thinks there are duplicates when i really want it to copy both into their respective name. I see two artifacts in the resolved configuration, both folders, but it appears that is not enough.
t
You want to copy from several configurations which contain artifact with same name?
j
Hi! No I have one configuration which I would like to use like the
implementation
configuration. One consumer consuming multiple artifacts using the same configuration name but not the same artifact name.
Copy code
// The consumer
dependencies {
   customImplementation(projects.projectA)
   customImplementation(projects.projectB)
}
Where
projectA
and
projectB
produce an artifact:
Copy code
val producerConfiguration = configurations.create(moduleProducer) {
    isCanBeResolved = true
    isCanBeConsumed = true
    attributes {
        attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(moduleProducer))
    }
}
Copy code
val assemble = register<Copy>(customAssemble) {
        dependsOn(assembleTasks)
        from(buildAssembledDir)
        into(buildOutputsDir)
    }

    artifacts {
        add(moduleProducer, assemble)
    }
The consumer links that with its own configuration:
Copy code
val implementationConfiguration = configurations.create(customImplementation) {
    isCanBeResolved = true
    isCanBeConsumed = false
    attributes {
        attribute(
            LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(
                LibraryElements::class.java,
                moduleProducer
            )
        )
    }
}
The problem is when i go to consume and copy the artifacts in the configuration, it puts it in the same folder
Copy code
register<Copy>(assembleCustom) {
        from(implementationConfiguration)

        into(depsFolder)

    }
t
and you want these artifacts to be inside different sub-folders inside
depsFolder
?
j
yes because they may contain files named the same which gradle complains about
I see the two artifacts in the configuration as a file named based on the folder i am copying but gradle tries to put the contents into the same directory.
Any help would be appreciated! Thanks!
t
Try to check eachFile() file method in
AbstractCopyTask
a
what about if the producer task, customAssemble, produced the output into a subdirectory based on the project name?
Copy code
val assemble = register<Copy>(customAssemble) {
  dependsOn(assembleTasks)
  from(buildAssembledDir) {
    into(project.name) // generate each project's output into a distinct dir
  }
  into(buildOutputsDir)
}
That way the output of each project will be in a distinct directory, so when you merge multiple directories together, the files won't clash?
j
Thank you, i’ll check them both out
@Adam S’s solution worked! thank you both!
👍 1