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

JacocoPluginExtension::applyTo can not be called from Kotlin #458

Closed
JLLeitschuh opened this issue Aug 10, 2017 · 6 comments
Closed

JacocoPluginExtension::applyTo can not be called from Kotlin #458

JLLeitschuh opened this issue Aug 10, 2017 · 6 comments

Comments

@JLLeitschuh
Copy link
Contributor

Expected Behavior

Ability to call:

jacoco {
    applyTo(tasks.matching { name == "junitPlatformTest" } as TaskCollection<*>)
}

OR:

jacoco {
    applyTo(tasks.matching { name == "junitPlatformTest" })
}

OR:

jacoco {
    applyTo(tasks.getByName("junitPlatformTest") as Task)
}

OR:

jacoco {
    applyTo(tasks.getByName("junitPlatformTest"))
}

This same problem exists even if you try wrapping the method names in backticks.

Current Behavior

When calling the applyTo with the signature <T extends Task & JavaForkOptions> void applyTo(TaskCollection tasks):

e: /Users/jonathanleitschuh/personal/git/shuffleboard/build.gradle.kts:102:13: Type inference failed: Not enough information to infer parameter T in fun <T : Task!> applyTo(tasks: TaskCollection<(raw) Task!>!): Unit where T : JavaForkOptions!
Please specify it explicitly.

When calling the applyTo with the signature <T extends Task & JavaForkOptions> void applyTo(final T task):

> Configure project :
e: /Users/jonathanleitschuh/personal/git/shuffleboard/build.gradle.kts:102:13: None of the following functions can be called with the arguments supplied: 
public open fun <T : Task!> applyTo(task: (???..???)): Unit where T : JavaForkOptions! defined in org.gradle.testing.jacoco.plugins.JacocoPluginExtension
public open fun <T : Task!> applyTo(tasks: TaskCollection<(raw) Task!>!): Unit where T : JavaForkOptions! defined in org.gradle.testing.jacoco.plugins.JacocoPluginExtension
Latest annotated tag is null. This does not match the expected version number pattern.

Context

I'm trying to configure Jacoco to run with Junit 5

Steps to Reproduce (for bugs)

See above.

Your Environment

  • Build scan URL:

Gradle version: 4.1.

@JLLeitschuh
Copy link
Contributor Author

JLLeitschuh commented Aug 17, 2017

This is the workaround code that I'm using and I know works:

/**
 * Workaround fix for calling [org.gradle.testing.jacoco.plugins.JacocoPluginExtension.applyTo]
 *
 * [Issue details here](https://github.com/gradle/kotlin-dsl/issues/458)
 */
fun org.gradle.testing.jacoco.plugins.JacocoPluginExtension.applyToHelper(task : Task) {
    val method = this::class.java.getMethod("applyTo", Task::class.java)
    method.invoke(this, task)
}

@JLLeitschuh
Copy link
Contributor Author

I think that this has been resolved? Not entirely sure. Are you waiting to close this until after there is a Gradle release with this fix?

@JLLeitschuh
Copy link
Contributor Author

In hindsight, this may have simply been my problem, not an issue with the compiler.
However, the type on the collection is wrong.

In my original example this didn't work which is sane because of the compiler:

jacoco {
    applyTo(tasks.getByName("junitPlatformTest") as Task)
}

This, on the other hand does work:

jacoco {
    applyTo(tasks.getByName("junitPlatformTest") as JavaExec)
}

Similarly, this didn't work:

jacoco {
    applyTo(tasks.matching { name == "junitPlatformTest" } as TaskCollection<*>)
}

But this does work:

jacoco {
    applyTo<JavaExec>(tasks.matching { name == "junitPlatformTest" })
}

The API in Gradle did need to be updated though. So we did the right thing there.

@eskatos eskatos added a:question and removed a:bug labels Sep 21, 2017
@eskatos eskatos modified the milestones: 1.0.0, 0.12.0 Sep 21, 2017
@eskatos
Copy link
Member

eskatos commented Sep 21, 2017

Thanks @JLLeitschuh for following up!

The Gradle API has not seen any recent changes wrt this issue. I believe it already worked as described in your last comment.

Closing

@eskatos eskatos closed this as completed Sep 21, 2017
@bamboo
Copy link
Member

bamboo commented Sep 21, 2017

@eskatos there is a related change pending on Gradle that I intended to follow up on: gradle/gradle@40d0906

@bamboo bamboo reopened this Sep 21, 2017
@bamboo bamboo self-assigned this Sep 21, 2017
@eskatos eskatos self-assigned this Sep 27, 2017
eskatos pushed a commit to gradle/gradle that referenced this issue Sep 27, 2017
By mentioning the type parameter `T` in the parameter list so it can be
inferred by a capable compiler.

See gradle/kotlin-dsl-samples#458
eskatos added a commit to gradle/gradle that referenced this issue Sep 27, 2017
By mentioning the type parameter `T` in the parameter list so it can be
inferred by a capable compiler.

See gradle/kotlin-dsl-samples#458
@eskatos
Copy link
Member

eskatos commented Sep 27, 2017

Fixed in upstream Gradle by gradle/gradle@f8f8618

Closing

@eskatos eskatos closed this as completed Sep 27, 2017
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