Crazyjavahacking Crazyjavahacking - 1 year ago 121
Groovy Question

Passing varargs as second argument in Groovy in Gradle Tooling API

I am trying to execute the Gradle Tooling API, but I am unable to call the

method as I am experiencing surprising issues during compilation:

buildscript {
repositories {
maven { url '' }

dependencies {
classpath "org.gradle:gradle-tooling-api:3.1"
classpath 'org.slf4j:slf4j-simple:1.7.10'

ext {

import org.gradle.tooling.*

task testGradleToolingAPI {
doLast {
ProjectConnection projectConnection = GradleConnector.newConnector()
.forProjectDirectory(GRADLE_PROJECT_HOME as File)

def operationTypes = [OperationType.TASK] as OperationType[]
println "operationTypes.class: ${operationTypes.class}"

.addProgressListener(new ApolloBuildProgressListener(), operationTypes)

finally {

class ApolloBuildProgressListener implements ProgressListener {
void statusChanged(ProgressEvent event) {
println "Progress event: ${event.description}"

The compilation fails as the vararg is not correctly recognized:

operationTypes.class: class [;
:testGradleToolingAPI FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/home/martin/devel/tmp/gradle-tooling-api/build.gradle' line: 36

* What went wrong:
Execution failed for task ':testGradleToolingAPI'.
> No signature of method: org.gradle.tooling.internal.consumer.DefaultBuildLauncher.addProgressListener() is applicable for argument types: (ApolloBuildProgressListener, [;) values: [ApolloBuildProgressListener@7c2dfa2, [TASK]]
Possible solutions: addProgressListener(, [;), addProgressListener(org.gradle.tooling.ProgressListener), addProgressListener(, addProgressListener(, java.util.Set)

What am I missing?

Answer Source

I'm guessing that ApolloBuildProgressListener is implementing org.gradle.tooling.ProgressListener when it should be Try this:

class ApolloBuildProgressListener implements {

Note that the BuildLauncher has four addProgressListener(...) methods. One accepts a org.gradle.tooling.ProgressListener and the other 3 accept a

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download