Gradle Task showing error when executing in the gradle build

Viewed 187

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
           }
        }
2 Answers

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.

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

Related