Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AbstractCopyTask.expand to be compatible with the Provider API #24268

Open
aSemy opened this issue Mar 9, 2023 · 2 comments
Open

Update AbstractCopyTask.expand to be compatible with the Provider API #24268

aSemy opened this issue Mar 9, 2023 · 2 comments
Labels
a:feature A new functionality in:file-tasks copy sync zip tar rename delete
Milestone

Comments

@aSemy
Copy link
Contributor

aSemy commented Mar 9, 2023

I want to use AbstractCopyTask.expand() to expand variables when I am Syncing files.

When I try and use providers as inputs for expand, they are accepted, but their values are not computed. Instead, expand() will instead just call toString() on the values, resulting in invalid data.

Example

// build.gradle.kts

val projectPath: Provider<String> = provider { project.path }

val mySyncTask by tasks.registering(Sync::class) {
  from(
    resources.text.fromString(
      "This file was created by project \${projectPath}"
    ).asFile()
  )
  into(temporaryDir)
  expand(
    "projectPath" to projectPath
  )

  doLast {
    temporaryDir.walk().filter { it.isFile }.forEach {
      println(it.readText())
    }
  }
}

Expected output:

> Task :mySyncTask
This file was created by project :

Current Behavior

The actual output does not compute the value of projectPath, resulting invalid output.

> Task :mySyncTask
This file was created by project fixed(class java.lang.String, :)

Context

Reproduced on Gradle 7.6 and 8.0.2

Workaround

As a workaround I have to compute the property in a doFirst {} block. This is unintuitive and confusing.

// build.gradle.kts

val projectPath: Provider<String> = provider { project.path }

val mySyncTask by tasks.registering(Sync::class) {
  from(
    resources.text.fromString(
      "This file was created by project \${projectPath}"
    ).asFile()
  )
  into(temporaryDir)

  // redefine the variable to be compatible Gradle Config Cache
  val projectPath = projectPath

  doFirst {
    expand(
      "projectPath" to projectPath.get()
    )
  }

  doLast {
    temporaryDir.walk().filter { it.isFile }.forEach {
      println(it.readText())
    }
  }
}

This produces the correct result

This file was created by project :
@aSemy aSemy added a:feature A new functionality to-triage labels Mar 9, 2023
@ov7a ov7a added in:file-tasks copy sync zip tar rename delete in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty and removed to-triage labels Mar 15, 2023
@ov7a
Copy link
Member

ov7a commented Mar 15, 2023

Thank you for your interest in Gradle!

This feature request is in the backlog of the relevant team but this area of Gradle is currently not a focus one so it might take a while before it gets implemented.

@lptr lptr added this to the 9.0 RC1 milestone May 30, 2023
@mlopatkin mlopatkin removed the in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty label May 30, 2023
@lptr
Copy link
Member

lptr commented May 30, 2023

In Gradle 9.0 we plan to migrate to MapProperty for expand which should cover this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature A new functionality in:file-tasks copy sync zip tar rename delete
Projects
None yet
Development

No branches or pull requests

4 participants