Thanks @Vampire, artifact transform is exactly what I was looking for.
We decided to create 2 different configurations, and apply transform for the one which we want to be extracted.
There is another issue that we are facing now while resolving the configurations. So consider configurations implementationAblSource
and compilePropath
, where compilePropath
extends implementationAblSource
.
Now, implementationAblSource
is transformed (extracted) and when resolving this configuration i.e. using implementationAblSource.files
is returning the transformed folders, but compilePropath.files
is still returning the files and not the transformed folders. Is this expected behavior or am I missing something?
Sample script used:
import org.gradle.api.artifacts.transform.TransformParameters
abstract class Unzip implements TransformAction<TransformParameters.None> {
@InputArtifact
abstract Provider<FileSystemLocation> getInputArtifact()
@Override
void transform(TransformOutputs outputs) {
def input = inputArtifact.get().asFile
println "input $input"
def unzipDir = outputs.dir(input.name)
println "unzipDir $unzipDir"
unzipTo(input, unzipDir)
}
private static void unzipTo(File zipFile, File unzipDir) {
// implementation...
}
}
def processed = Attribute.of('processed', Boolean)
def artifactType = Attribute.of('artifactType', String)
configurations{
implementationAblSource{
canBeResolved=true
attributes.attribute(processed, true)
}
compilePropath{
canBeResolved=true
}
compilePropath.extendsFrom(implementationAblSource)
}
dependencies {
attributesSchema {
attribute(processed)
}
artifactTypes.create("pl")
artifactTypes.getByName("pl") {
attributes.attribute(processed, false);
}
registerTransform(Unzip) {
from.attribute(processed, false).attribute(artifactType, "pl")
to.attribute(processed, true).attribute(artifactType, "pl")
}
}
dependencies {
implementationAblSource ('<group>:<module1>:<version>:<classifier>@pl')
implementationAblSource ('<group>:<module2>:<version>:<classifier>@pl')
}
println configurations.implementationAblSource.files //prints the transformed folders
println configurations.compilePropath.files //prints the module files