Hello. Is it possible to do a lazy artifact transf...
# community-support
s
Hello. Is it possible to do a lazy artifact transform? What I actually mean: there is a JAR dependency from remote repository that needs to be unpacked in a task. The problem is that it's eagerly resolved during
CONFIGURING
phase, not
EXECUTING
like e.g. regular compilation dependency. The problem is that the artifact is quite big and it's resolved in a single-thread CONFIGURING phase (while potentially it could be multi-thread EXECUTING). I tried this approach:
Copy code
configurations {
    remoteApp {
        attributes {
            attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "unzipped")
        }
    }
}

dependencies {
    // example from <https://docs.gradle.org/current/userguide/artifact_transforms.html#artifact_transforms_without_parameters>
    // public abstract class Unzip implements TransformAction<TransformParameters.None> {
    registerTransform(Unzip) {
        from.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "jar")
        to.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, "unzipped")
    }

    // libs is toml version catalog
    remoteApp libs.remoteApp
}

def unpackRemoteAppTask = tasks.register('unpackRemoteApp', Copy.class) {
    from({ configurations.remoteApp })
    into layout.buildDirectory.dir("remoteapp/x86")
    fileMode = 0755
    dirMode = 0755
}
I've found that according to documentation, the artifact transform is applied before resolving the task input, but can it become lazy?
v
The artifact transform is done when you request the artifacts, so it already is as lazy as possible. If you request the files at configuration phase, Gradle has no other choice than executing the transform.
I guess you use configuration cache, there most resolution is done indeed at the end of the configuration phase as the result of resolution is stored to the configuration cache to not do it each time but just reuse the result, and thus also artifact transforms as they are part of the resolution process.
s
You are right! Thanks, that's a good point. Without the configuration cache it behaves as expected.
👌 1