Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Gradle should accept Kotlin lambdas as a lazy construct for e.g. files #1077

Closed
eskatos opened this issue Aug 28, 2018 · 4 comments
Closed
Assignees
Labels
Milestone

Comments

@eskatos
Copy link
Member

eskatos commented Aug 28, 2018

Expected Behavior

val srcDir = file("src")
val collection = layout.files({ srcDir.listFiles() })
println(collection.files)

Current Behavior

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':foo'.
> Cannot convert the provided notation to a File or URI: () -> kotlin.Array<(out) java.io.File!>!.

Context

See https://docs.gradle.org/current/userguide/working_with_files.html#example_implementing_a_file_collection

The file notation conversion unpacks Groovy Closures, one can expect it to also unpack Kotlin lambdas. This applies to many other APIs, see e.g. https://docs.gradle.org/current/userguide/working_with_files.html#sec:specifying_multiple_files

Your Environment

Gradle 4.10

@eskatos
Copy link
Member Author

eskatos commented Aug 28, 2018

The file notation conversion also unpacks Provider<T>s. This allows the following:

val srcDir = file("src")
val collection = layout.files(provider { srcDir.listFiles() })
println(collection.files)

@eskatos
Copy link
Member Author

eskatos commented Aug 30, 2018

What makes this confusing is that the complete error message:

* What went wrong:
Cannot convert the provided notation to a File or URI: () -> kotlin.Array<(out) java.io.File!>!.
The following types/formats are supported:
  - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
  - A String or CharSequence URI, for example 'file:/usr/include'.
  - A File instance.
  - A Path instance.
  - A Directory instance.
  - A RegularFile instance.
  - A URI or URL instance.

doesn't mention Callable nor Provider nor collections or arrays.

@eskatos eskatos added this to the 1.0-RC4 milestone Aug 30, 2018
@bamboo bamboo self-assigned this Aug 30, 2018
@eskatos eskatos modified the milestones: 1.0-RC4, 1.0-RC5 Sep 11, 2018
bamboo added a commit to gradle/gradle that referenced this issue Sep 14, 2018
bamboo added a commit to gradle/gradle that referenced this issue Sep 28, 2018
@eskatos eskatos modified the milestones: 1.0-RC12, 1.0.0 Oct 1, 2018
@eskatos eskatos modified the milestones: 1.0.0, 1.0.1, 1.1.0 Oct 26, 2018
@eskatos eskatos changed the title FileCollections cannot be created from Kotlin lambda Gradle should accept Kotlin lambdas as a lazy construct for e.g. files Nov 6, 2018
@JLLeitschuh
Copy link
Contributor

@eskatos The error message also doesn't mention that it can accept collections of any of those items as well.

bamboo added a commit to gradle/gradle that referenced this issue Nov 13, 2018
- Let `PathNotationConverter` handle result of `Callable`/`Closure` uniformly
- Allow Kotlin lambda as deferred path/file notation

Resolves gradle/kotlin-dsl-samples#1077
@eskatos eskatos self-assigned this Dec 6, 2018
bamboo added a commit to gradle/gradle that referenced this issue Dec 6, 2018
@eskatos
Copy link
Member Author

eskatos commented Dec 8, 2018

Done in gradle/gradle#7739 and gradle/gradle#7966

@eskatos eskatos closed this as completed Dec 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants