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

tasks.regiser<T>(name) returns NamedDomainObjectProvider instead of TaskProvider #1108

Closed
JLLeitschuh opened this issue Sep 13, 2018 · 3 comments

Comments

@JLLeitschuh
Copy link
Contributor

This is the example code I'm working from:

val sourceJar =
    tasks.register<Jar>("sourceJar") {
        group = LifecycleBasePlugin.BUILD_GROUP
        description = "An archive of the source code"
        classifier = "sources"
        from(java.sourceSets["main"].allSource)
    }

Expected Behavior

sourceJar in the example should be of type TaskProvider<Jar>

Current Behavior

sourceJar in the example above should not return the less specific typeNamedDomainObjectProvider<Jar>

Context

With the addition of the TaskProvider API, I'm concerned that future API's will constrain the inputs of lazy task's to only accept TaskProvider which will prevent objects created through tasks.register to be passed without casting.

Your Environment

------------------------------------------------------------
Gradle 4.10
------------------------------------------------------------

Build time:   2018-08-27 18:35:06 UTC
Revision:     ee3751ed9f2034effc1f0072c2b2ee74b5dce67d

Kotlin DSL:   1.0-rc-3
Kotlin:       1.2.60
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_92 (Oracle Corporation 25.92-b14)
OS:           Mac OS X 10.13.6 x86_64
@StefMa
Copy link
Contributor

StefMa commented Sep 16, 2018

Is that a issue for the Kotlin DSL?
You simply call this method which is a API call from gradle/gradle, no? 🤔

Anyway. The following buildscript gives the correct output:

plugins {
  java
}

val sourceJar =
    tasks.register<Jar>("sourceJar") {
        group = LifecycleBasePlugin.BUILD_GROUP
        description = "An archive of the source code"
        classifier = "sources"
        from(sourceSets["main"].allSource)
    }

println(sourceJar)
println(sourceJar is TaskProvider<Jar>)

(with Gradle 4.10.1):

> Configure project :
provider(task sourceJar, class org.gradle.api.tasks.bundling.Jar)
true

@JLLeitschuh
Copy link
Contributor Author

It's because there's a reified extension function, but not one for TaskContainer.

The runtime type is correct, but the compile time type is not.

@eskatos eskatos self-assigned this Sep 17, 2018
@eskatos eskatos added this to the 1.0-RC7 milestone Sep 17, 2018
eskatos added a commit that referenced this issue Sep 17, 2018
#1108

Signed-off-by: Paul Merlin <paul@gradle.com>
eskatos added a commit that referenced this issue Sep 17, 2018
@eskatos
Copy link
Member

eskatos commented Sep 18, 2018

Closing as fixed in #1116

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

No branches or pull requests

3 participants