0

I have a groovy class "Utils.groovy" which contains the method "makeHttpCall()". This is a summarized version of the method:

static String makeHTTPCall() {
    ...
    request.setHeader(javax.ws.rs.core.HttpHeaders.AUTHORIZATION, authHeader)
    ...
}

The compiler complains:

Groovy:Apparent variable 'javax' was found in a static scope but doesn't refer to a local variable, static field or class.

If I make the method non-static though, it will stop complaining;

String makeHTTPCall() {
    ...
    request.setHeader(javax.ws.rs.core.HttpHeaders.AUTHORIZATION, authHeader)
    ...
}

this way it doesn't complain. Why does the compiler complain about this?

Note that the method runs with no problems; it is run as part of a Jenkins shared library.

Thanks!

EDIT: Using import javax.ws.rs.core.HttpHeaders gives

Groovy:unable to resolve class javax.ws.rs.core.HttpHeaders

So that class is not resolvable by the compiler, but it is when run inside Jenkins.

1 Answers1

0

You need to add the library that provides "javax.ws.rs.core.HttpHeaders" to your project's buildpath. Alternatively, you can use an @Grab to your class/script. This is probably not what you want in this case since Jenkins is providing that dependency at runtime.

emilles
  • 1,104
  • 7
  • 14