javaspring-bootcodeql

Sample Codeql Query for SpringBootApplication


I am trying to learn Codeql analysis tool and running into some issues while running the query.

I am able to successfully create the database upon running the command:

 codeql database create

But when I run the query:

codeql query run db-name

I keep getting the error 'could not resolve the module java' but I see the java folder in the codeql that I had extracted after initial installation.

Any pointers to resolve this is highly appreciated.

Thank you

Here is a sample application I have:

@SpringBootApplication
public class myApplication{
  public satic void main (String args[]){
     SpringApplication.run(myApplication.class, args);
  }
}

And here is a sample query I found on github that I am trying to run. This is supposed to return classes annotated with SpringBootApplication

import java

class SpringBootApplication extends Class{
  SpringBootApplication(){
    exists(Annotation annot |
     annot.getType().getName() = "SpringBootApplication" and
     annot.getAnnotatedElement() = this
   )
  }
}

Solution

  • I was able to resolve it and here's how I did it:

    1. Placed qlpack.yml file in my code repository with following contents:
    name: java-queries
    version: 1.0.0
    dependencies:
      codeql/java-queries:*.*
    
    1. Run the command : codeql pack install

    Hope this helps anyone else who runs into this issue.