Java: Include Gradle dependencies in CodeQL database #8352
Marcono1234
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Bear in mind it isn't necessary for the build of both projects to happen in a single Gradle run. You could simply make a small shell script that builds GSON using Maven and then your project using Gradle, or pass the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Because CodeQL only includes files which are compiled during build in the database, a query might not yield all desired results in case dataflow or taintflow occurs in a third party dependency and CodeQL itself does not model that dependency.
Therefore I tried to see whether it is possible to modify a Gradle build to also compile the sources of dependencies. The result is the following Gradle Kotlin DSL buildscript modification:
This is probably a rather hacky and unreliable solution (suggestions are welcome), but for a small demo project using Gson, this seemed to work fine. It works by requesting the source artifacts of the dependencies, including them with
javac
's--source-path
, and removing the corresponding JAR artifact from the classpath. I chose--source-path
here because it only specifies where source files can be found, without requiring all of them to be compiled (in case they are not used). For example if the main Java sources only use Gson'sFieldNamingPolicy
, then only the classesFieldNamingPolicy
andFieldNamingStrategy
(the superinterface) are compiled.There are however some limitations:
compileJava
task; for a real project this is most likely not desired and instead a separate task should be used.--source-path
approach might not actually be that efficient compared to treating the third-party sources as regular main sources and might still end up compiling large parts of the complete sources of the dependencies..class
files instead of.java
files #5556) with CodeQL where it does not extract source files specified by--source-path
if amodule-info.java
file is present. The script above currently tries to work around that, but it might not be able to handle all cases.Hopefully this is nonetheless useful for someone :)
Beta Was this translation helpful? Give feedback.
All reactions