Automatically generate extensions for all `Action` based Gradle API methods #117

Closed
bamboo opened this Issue Aug 25, 2016 · 0 comments

Projects

None yet

1 participant

@bamboo
Member
bamboo commented Aug 25, 2016 edited

Extensions should be generated on first access and then cached just like the gradle-script-kotlin-api.jar.

@bamboo bamboo added this to the 0.3.2 milestone Aug 25, 2016
@bamboo bamboo self-assigned this Aug 25, 2016
@bamboo bamboo added a commit that referenced this issue Aug 25, 2016
@bamboo bamboo Compile scripts against generated Kotlin API jar
We would like Kotlin build scripts to behave as if all the `Action<T>`
parameters in the Gradle API had been declared as `T.() -> Unit` to
avoid the need for explicitly qualifying the single argument to the
given lambda expressions with `it`.

In other words, we would like users to be writing code like:

    copySpec {
       from("src")
       into("out")
    }

Instead of:

    copySpec {
        it.from("src")
        it.into("out")
    }

Where `copySpec` is declared in the Gradle Java API as:

    CopySpec copySpec(Action<? super CopySpec> configuration)

So far we have been able to avoid the qualifying `it` in some situations
via mindful use of inheritance and Kotlin extensions but a comprehensive
solution was still lacking. The underlying issue is that while Kotlin
does provide a type extension mechanism, type members still take
precedence over extensions and currently there's no mechanism to
instruct Kotlin otherwise.

In the future we might be able to implement a different solution to this
particular issue via a new Kotlin language feature still in discussion:

 -  https://youtrack.jetbrains.com/issue/KT-12848

In the meantime, by giving the Kotlin compiler a carefully crafted API
jar with all members that could potentially conflict with our provided
extensions removed we can work around the fact that interface members
take precedence over extension members and expose all the extensions we
want.

And that is the solution implemented in this commit:

  - Remove all API methods that take a last `Action<T>` parameter
  - Generate shim extensions that take a last `T.() -> Unit`

Proper treatment for generic types will be implemented in a future
commit.

Resolves: #52
See also: #54, #117
7b3890e
@bamboo bamboo added a commit that referenced this issue Aug 29, 2016
@bamboo bamboo Generate Action<T> extensions at runtime
This ensures the generated extensions match the Gradle API being used by
the build script.

See: #117
8b6091e
@bamboo bamboo added a commit that referenced this issue Sep 2, 2016
@bamboo bamboo Support navigating to generated extensions sources
See #117
d09e89f
@bamboo bamboo added a commit that referenced this issue Sep 2, 2016
@bamboo bamboo Extract `ApiJar` and `ApiExtensionsJar` modules
See: #117
2407b8d
@bamboo bamboo added a commit that referenced this issue Sep 2, 2016
@bamboo bamboo Include documentation in generated API extensions
See: #117
bf1c22a
@bamboo bamboo added a commit that referenced this issue Sep 6, 2016
@bamboo bamboo Add notice to each generated extension
See: #117
d67bef0
@bamboo bamboo closed this Sep 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment