"Reference not found" Error for ant.references.classpath

I have code snippet

ant.path(id: ‘classpath’, location: ‘/opt/apps/jenkins/local-repo/sourceanalyzer.jar’)

ant.taskdef(name: ‘sca’, classname: ‘com.fortify.dev.ant.SourceanalyzerTask’, classpath: configurations.classpath.asPath)

ant.sca(buildid: buildid , jdk: “1.5”) {

fileset(dir: ‘src’) {

include(name: ‘**/.’)

}

classpath(refid: ant.references.classpath)

}

I got the Error saying

Referece /opt/apps/jenkins/local-repo/sourceanalyzer.jar not found.

Please let me know what am I missing here.

The error is at line

classpath(refid: ant.references.classpath)

Instead of declaring an Ant path I’d declare a custom configuration that you can assign the Ant task library to. You should also prefer to reference the Fortify dependency located on specific repository (e.g. Maven Central or a file location that is available to all developers as well as the CI server).

Example:

configurations {
    fortify
    }
  dependencies {
    fortify '...'
}
  repositories {
    mavenCentral()
}
  ant.taskdef(name: 'sca', classname: 'com.fortify.dev.ant.SourceanalyzerTask', classpath: configurations.fortify.asPath)

Please make sure to use the code tabs in the future if you include source code. Otherwise, it’s really hard to read.

The ant Path I declared is not for defining task. my actual code as follows

configurations {
    classpath
}
dependencies {
    classpath fileTree(dir: '/opt/apps/jenkins/local-repo', include: 'sourceanalyzer.jar')
}
  repositories {
    flatDir(dirs: '/opt/apps/jenkins/local-repo')
}
    task sc
 {
   doLast {
      def buildid = project.name
     ant.property(name: 'lib', location: '/opt/apps/JavaTools/Fortify/Core/lib/sourceanalyzer.jar')
     ant.property(name:'sourceanalyzer.command', location: '/opt/apps/JavaTools/Fortify/bin/sourceanalyzer')
           println ant.properties['lib']
       ant.path(id: 'classpath', location: '/opt/apps/jenkins/local-repo/j2ee.jar')
      ant.taskdef(name: 'sca', classname: 'com.fortify.dev.ant.SourceanalyzerTask', classpath: configurations.classpath.asPath)
         println("build Dir ===="+buildDir)
       ant.sca(clean: "true")
    ant.sca(buildid: buildid , jdk: "1.5") {
        fileset(dir: 'src') {
            include(name: '**/*.*')
      }
       classpath(refid: ant.references.classpath)
        }
     ant.sca(buildid: buildid , jdk: "1.5" ,
scan: "true", findbugs: "true" , javaBuildDir: buildDir, resultsfile:"fortify_reports/issues.fpr", htmlReport: "true" )
 }
//doLast
} //sc

Can you provide us with an example project preferably on GitHub that reproduces the issue? I think I’d need to play around with it.