How do I insert a TransformAction between two TransformActions?

I want to perform some transformation operations between two existing TransformActions. How do I insert a TransformAction between two TransformActions?

I read this Configure multiple TransformActions to process artifact in chain, but I still don’t quite understand how to do it.

Artifact transforms transform one set of attribute values to another set of attribute values, so you just have to build a chain.
In the example in the linked thread to work properly it should for example be

    project.dependencies.registerTransform(FooTransformAction::class.java) { spec ->
      spec.from.attribute(artifactType, "jar")
      spec.to.attribute(artifactType, "foo-jar")
    }

    project.dependencies.registerTransform(BarTransformAction::class.java) { spec ->
      spec.from.attribute(artifactType, "foo-jar")
      spec.to.attribute(artifactType, "processed-jar")
    }

Yes. I want to insert a transfrom between FooTransformAction and BarTransformAction, but it don’t work.

Original chain:FooTransformAction → BarTransformAction
I want the chain: FooTransformAction → MyTransformAction → BarTransformAction

So i don’t know how to do it.

MyTransformAction like this:

project.dependencies.registerTransform(MyTransformAction::class.java) { spec ->
  spec.from.attribute(artifactType, "foo-jar")
  spec.to.attribute(artifactType, "foo-jar")
}

abstract class MyTransformAction: TransformAction<TransformParameters.None> {

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

    override fun transform(transformOutputs: TransformOutputs) {
        val input = inputArtifact.get().asFile
        when {
            input.isDirectory -> transformOutputs.dir(input)
            input.isFile -> transformOutputs.file(input)
            else -> throw IOException("Expecting a file or a directory: ${input.canonicalPath}")
        }
    }
}

You tell Gradle your transform isn’t doing anything, so it will never be selected for any artifact. And if foo and bar are already registered, I don’t think you can squeeze in.

All right. Thank you very much. And is there any other way?

Maybe if you register one transform, that directly transforms from source to target state. That transform could then first call foo, do its own logic and the call bar. As the shortest chain wins the selection, it would be selected.

OK, Thank you very much again.