how to fix groovy.lang.MissingMethodException: No signature of method:

后端 未结 5 1580
悲&欢浪女
悲&欢浪女 2020-12-15 16:23

I am trying to use this method without a closure

def copyAndReplaceText(source, dest, targetText, replaceText){
    dest.write(source.text.replaceAll(target         


        
相关标签:
5条回答
  • 2020-12-15 16:42

    To help other bug-hunters. I had this error because the function didn't exist.

    I had a spelling error.

    0 讨论(0)
  • 2020-12-15 16:45

    You can also get this error if the objects you're passing to the method are out of order. In other words say your method takes, in order, a string, an integer, and a date. If you pass a date, then a string, then an integer you will get the same error message.

    0 讨论(0)
  • 2020-12-15 16:51

    Because you are passing three arguments to a four arguments method. Also, you are not using the passed closure.

    If you want to specify the operations to be made on top of the source contents, then use a closure. It would be something like this:

    def copyAndReplaceText(source, dest, closure){
        dest.write(closure( source.text ))
    }
    
    // And you can keep your usage as:
    copyAndReplaceText(source, dest){
        it.replaceAll('Visa', 'Passport!!!!')
    }
    

    If you will always swap strings, pass both, as your method signature already states:

    def copyAndReplaceText(source, dest, targetText, replaceText){
        dest.write(source.text.replaceAll(targetText, replaceText))
    }
    
    copyAndReplaceText(source, dest, 'Visa', 'Passport!!!!')
    
    0 讨论(0)
  • 2020-12-15 16:52

    In my case it was simply that I had a variable named the same as a function.

    Example:

    def cleanCache = functionReturningABoolean()
    
    if( cleanCache ){
        echo "Clean cache option is true, do not uninstall previous features / urls"
        uninstallCmd = ""
        
        // and we call the cleanCache method
        cleanCache(userId, serverName)
    }
    ...
    

    and later in my code I have the function:

    def cleanCache(user, server){
    
     //some operations to the server
    
    }
    

    Apparently the Groovy language does not support this (but other languages like Java does). I just renamed my function to executeCleanCache and it works perfectly (or you can also rename your variable whatever option you prefer).

    0 讨论(0)
  • 2020-12-15 17:04

    This may also be because you might have given classname with all letters in lowercase something which groovy (know of version 2.5.0) does not support.

    class name - User is accepted but user is not.

    0 讨论(0)
提交回复
热议问题