Plugin create configuratation

Hi, does anyone know how to recover a configuration file without using the function afterEvaluate

Here is my plugin

class MyPlugin : Plugin<Project> {
    override fun apply(project: Project) {

        project.plugins.apply(JavaLibraryPlugin::class.java)

        val pluginExtension= project.configurations.create("thrift")

        project.afterEvaluate { 
           project.configuraThrift(pluginExtension)
        }

    }

When I try without afterEvaluate

class MyPlugin : Plugin<Project> {
    override fun apply(project: Project) {

        project.plugins.apply(JavaLibraryPlugin::class.java)
        project.plugins.apply(MavenPublishPlugin::class.java)

         val pluginExtension= project.configurations.create("thrift")

        
        project.configuraThrift(pluginExtension)


    }
}

I have following error

* What went wrong:
A problem occurred evaluating script.
> Cannot change resolution strategy of dependency configuration ':thrift' after it has been resolved.

In my function configuraThrift I have

internal fun Project.configuraThrift() {
tasks.register("copyThriftDeps", Sync::class.java) {
        it.duplicatesStrategy = DuplicatesStrategy.INCLUDE

        it.from(pluginExtension.map { tarTree(it) })
        it.into(layout.buildDirectory.get().dir(Configure.THRIFT_DEPS))

        it.doLast {
            print("* copie des dépendances thrift")
        }
    }
}

Tanks, Beni

Your problem is the .map.
It is not the lazy .map on Provider, but the eager Iterable<File>.map by Kotlin stdlib.

One option would be to not use a task to unpack, but an artifact transform.

Another would be to use .elements before you map to have a lazy Provider.

I take first option
Maybe somthing like this :

val thriftModuleAttribute = Attribute.of("thrift", Boolean::class.javaObjectType)


        project.configurations.create("thrift"){
            it.attributes.attribute(thriftModuleAttribute,true)

        }

        project.dependencies.registerTransform(ThriftModuleTransform::class.java) {
            it.from.attributes.attribute(ARTIFACT_TYPE_ATTRIBUTE, "thrift").attribute(thriftModuleAttribute, true)
            it.to.attributes.attribute(ARTIFACT_TYPE_ATTRIBUTE, "thrift").attribute(thriftModuleAttribute, false)
        }

Something like that, yes.
Afair the docs even use an Unzip transform as one of the examples.

Tanks for the tips.
In my exemple registerTransform seem not to be trigered

  val thriftModuleAttribute = Attribute.of("thrift", Boolean::class.javaObjectType)





        project.configurations.create("thrift") {
            it.attributes.attribute(thriftModuleAttribute, true)
            it.isCanBeResolved = false
            it.isCanBeConsumed= false


        }




        project.dependencies.registerTransform(ThriftModuleTransform::class.java) {
            it.parameters {ti ->
                ti.outputPath  = project.layout.buildDirectory.dir(Configure.THRIFT_SRC).get().asFile.toPath()
            }
            it.from.attributes.attribute(ARTIFACT_TYPE_ATTRIBUTE, "jar").attribute(thriftModuleAttribute, true)
            it.to.attributes.attribute(ARTIFACT_TYPE_ATTRIBUTE, "jar").attribute(thriftModuleAttribute, false)
        }

I hava a task that depend on the transformation but the dir is never created

abstract class ThriftModuleTransform : TransformAction<ThriftModuleTransform.MyParameters> {

    interface MyParameters : TransformParameters {
        @get:Input
        var outputPath: Path


    }

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

    @get:Inject
    abstract val archiveOperations: ArchiveOperations


    override fun transform(outputs: TransformOutputs) {



        val files = archiveOperations.tarTree(inputArtifact)


        outputs.dir(parameters.outputPath).mkdirs()

        files.forEach {
            outputs.file(parameters.outputPath.resolve(it.name)).writeText(it.readText())
        }

    }
}

Because if that is all, you miss half of the parts and have errors.
You request “true” and your transformation transforms from “true” to “false”.
So even if you would set the attribute on the jar artifacts as in the documentation, the transform would never trigger.
Currently you request “true” and get the jars because they do not have the attribute at all and absent is compatible to any value.