2

The error that i am facing is the class java.lang.Integer cannot be cast to class java.lang.String. when running gradle test -Pnum=10. This is my code:

     def fibo(n){
 //something
        }
    }
        task test() {
           doLast {
               fibo num
           }
        }
Aminator
  • 160
  • 1
  • 1
  • 11

2 Answers2

1

When entering the value of num using the parameter -Pnum=10, num will be a String, but you need an Integer.

Changing the task test like this should fix it:

task test() {
   doLast { 
       fibo num.toInteger()
   }
}

See this answer for more information about converting a String to an Integer in Groovy.

thokuest
  • 5,800
  • 24
  • 36
Tobias
  • 2,547
  • 3
  • 14
  • 29
0

Cast you argument to integer before using, as its passed as string int nValue = Integer.valueOf(n);

Soni
  • 142
  • 8