prime
prime

Reputation: 799

How to add a project to Gradle settings programmatically

I want to include a project for my settings.gradle programmatically.

This is what I tried.

def testArray = ["A", "B", "C"] as String[]
Settings.include(testArray)

But this gives me below error.

* What went wrong:
A problem occurred evaluating script.
> No signature of method: static org.gradle.api.initialization.Settings.include() 
  is applicable for argument types: ([Ljava.lang.String;) values: [[A, B, C]]

What am I doing wrong here?

I tried many ways[1] to define an array, but every time it is taken as a list. :(

[1] http://grails.asia/groovy-array-manipulation-examples

Upvotes: 0

Views: 267

Answers (1)

Cisco
Cisco

Reputation: 22952

Settings does not have an include method that accepts a String[] array.

https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/Settings.html

You need to translate/convert the array into varargs using the * spread operator:

def testArray = ["A", "B", "C"] as String[]
include(*testArray)

Upvotes: 2

Related Questions