This message was deleted.
# community-support
s
This message was deleted.
a
try using
configurations.bundledApps.incoming.artifactFiles
to get the incoming files (or something similar - I often get muddled with area of Gradle)
a
@Adam Thanks for the tip. I was unfamiliar with that. I'm still getting the same error after using that method
Copy code
configurations.bundledApps.incoming.files.each { file -> 
	distributions.main.contents {
		from(zipTree(file)) {
			into "tools"
		}
	}
}
a
possibly using
each {}
means Gradle loses the task dependency. Try using
incoming.resolvedArtifacts
(or something like that, you want one that returns a
Provider<>
), and you can unzip the files in a
map {}
, then pass the result into the distributions contents something like this:
Copy code
distributions.main.contents {
  from(configurations.bundledApps.incoming.resolvedArtifacts.map { files -> ... }) {
    into "tools"
  }
}
v
Or maybe better, use an artifact transform to do the unzipping.
a
@Adam I suspect you're onto something. I included this in the first
distributions
declaration and it builds in correct order
from(configurations.bundledApps.singleFile){ into "tools" }
🚀 1
@Vampire I looked into artifact transforms and I'm not quite following how I'd use it to unzip them.
v
The unzipping is even on of the examples in the documentation
And I also did it some years ago where I needed it
artifact transform is what you want
Then you also do not need to unpack the same archives again and again on every build
a
@Adam Digging into this a bit more seems to be revealing that
zipTree
is what's breaking task order resolution. The consuming task knows where the file should be based upon the output of that task. But Gradle is not executing that task first.
v
Use an artifact transform and it will work 😉
a
Do you have a suggestion for a built-in to do the unzipping?
v
Here a Kotlin variant with optionally stripping the top-level directory:
Copy code
abstract class Unzip : TransformAction<Parameters> {
    @get:Inject
    protected abstract val fileSystem: FileSystemOperations

    @get:Inject
    protected abstract val archive: ArchiveOperations

    @get:InputArtifact
    abstract val inputArtifact: Provider<FileSystemLocation>

    override fun transform(outputs: TransformOutputs) {
        val input = inputArtifact.get().asFile
        val output = outputs.dir(input.name)
        fileSystem.sync {
            from(archive.zipTree(input))
            into(output)
            if (parameters.stripTopLevelDirectory.getOrElse(false)) {
                eachFile {
                    val segments = relativePath.segments
                    relativePath = RelativePath(
                        relativePath.isFile,
                        *segments.sliceArray(1 until segments.size)
                    )
                }
            }
        }
    }

    interface Parameters : TransformParameters {
        @get:Optional
        @get:Input
        val stripTopLevelDirectory: Property<Boolean>
    }
}
a
Awesome. Thanks!