Groovy: Method definition not expected here
<p>I'm sure this is a simple fix but I'm new to programming in general and Groovy in particular. </p>

<p>I am trying to follow <a href="https://jenkins.io/blog/2016/07/18/pipline-notifications/" rel="noreferrer">this guide</a> to enable slack notifications in a Jenkins 2 pipeline job but pasting and customizing the final code block is giving me the following error;</p>

<pre><code>Method definition not expected here. Please define the method at an appropriate place or perhaps try using a block/Closure instead.
</code></pre>

<p>This is my code right now, although I've substituted a few bits for security. The error is occurring at the <code>def notifyBuild(String buildStatus = 'STARTED') {</code> line.</p>

<pre><code>node('on-demand-t2large'){
    stage ('Checkout') {
        checkout( checkout stuff here )
    }

    stage ('Build') {
        try {
            notifyBuild('STARTED')

            dir("place") {
                sh 'script name'
            } 
        }
        catch (e) {
            // If there was an exception thrown, the build failed
            currentBuild.result = "FAILED"
            throw e
        } 
        finally {
            // Success or failure, always send notifications
            notifyBuild(currentBuild.result)
        }

        def notifyBuild(String buildStatus = 'STARTED') {
            // build status of null means successful
            buildStatus =  buildStatus ?: 'SUCCESSFUL'

            // Default values
            def colorName = 'RED'
            def colorCode = '#FF0000'
            def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
            def summary = "${subject} (${env.BUILD_URL})"
            def details = """&lt;p&gt;STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':&lt;/p&gt;
            &lt;p&gt;Check console output at &amp;QUOT;&lt;a href='${env.BUILD_URL}'&gt;${env.JOB_NAME} [${env.BUILD_NUMBER}]&lt;/a&gt;&amp;QUOT;&lt;/p&gt;"""

            // Override default values based on build status
            if (buildStatus == 'STARTED') {
                color = 'YELLOW'
                colorCode = '#FFFF00'
            } else if (buildStatus == 'SUCCESSFUL') {
                color = 'GREEN'
                colorCode = '#00FF00'
            } else {
                color = 'RED'
                colorCode = '#FF0000'
            }

            // Send notifications
            slackSend (channel: '@me', color: colorCode, message: summary)
        }
    } 
}
</code></pre>

<p>I understand from some googling that groovy doesn't accept inner class definition, but as new as I am to programming I don't know how to fix it. Any help (with explanations so I can learn!) would be appreciated. </p>