github / codeql-action

Actions for running CodeQL analysis
MIT License
1.14k stars 316 forks source link

codeql-cli-2.17.6 broken kotlin-java build in multi-module project #2360

Closed serpro69 closed 3 months ago

serpro69 commented 3 months ago

I have a multi-module kotlin project, where modules require different java versions (8, 11, ...) I noticed that my codeql actions started failing and since I haven't made any changes to build configuration between last successful build and currently failed one, I've started looking at the version of the action. While I can't spot anything in the logs, the last version that worked for me was codeql-cli-2.17.3, and after setting that up explicitly the build works again. With the current codeql-cli-2.17.6 , the build breaks with the following error:

[2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild] FAILURE: Build failed with an exception.
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild] * What went wrong:
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild] A problem occurred configuring project ':cli-bot'.
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild] > Could not resolve all files for configuration ':cli-bot:classpath'.
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]    > Could not resolve org.graalvm.buildtools:native-gradle-plugin:0.10.1.
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]      Required by:
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]          project :cli-bot > org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.10.1
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]       > No matching variant of org.graalvm.buildtools:native-gradle-plugin:0.10.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]           - Variant 'apiElements' capability org.graalvm.buildtools:native-gradle-plugin:0.10.1 declares a library, packaged as a jar, and its dependencies declared externally:
  [2024-06-29 13:35:18] [build-stdout] [2024-06-29 13:35:18] [autobuild]               - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8

This is a successful run after downgrading the codeql tooling to 2.17.3 and using github/codeql-action/init@v3.25.6 version explicitly - https://github.com/serpro69/kotlin-faker/actions/runs/9724606568 If I use init@v3 and do not set tool version, which currently defaults to 2.17.6, the build fails to compile due to java version that is being picked up: https://github.com/serpro69/kotlin-faker/actions/runs/9724530099/job/26840837224

The problem is, with the current version, it's setting java8 by default, for some reason - https://github.com/serpro69/kotlin-faker/actions/runs/9724530099/job/26840837224#step:5:81 , and I do not see a way how to override that. That wasn't the case previously, so gradle would just pick whichever version is needed, based on toolchains and gradle setup.

Is this intended behavior? Is there any way I can upgrade to latest version while preserving the previous behavior?

smowton commented 3 months ago

This is because we're now recognising the configuration in the root build.gradle.kts file to compile against Java 8. The best way to override this is to use a setup-java step to install the JDK version that your project requires.

serpro69 commented 3 months ago

Hi @smowton , Thanks for the reply!

I've tried adding setup-java step actually. The thing is, as mentioned above, I need several java versions, e.g. 8 and 11 to build the whole project, due to some gradle plugins compatibility nonsense. And if I install several versions with setup-java, the action still defaults to java8.

smowton commented 3 months ago

Tricky. How about installing both, but then twiddling ~/.m2/toolchains.xml to only list Java 11? I think Gradle will still find Java 8 by exploring the platform default JDK directory.

serpro69 commented 3 months ago

Hmm, let me try that :) Thanks for the suggestion.

serpro69 commented 3 months ago

OK, what I tried now is just to setup only one java version via setup-java, instead of multiple, and that worked for my case. Codeql recognized the installed java version and didn't default to java 8, at the same time, the gradle plugin which requires me to have java 11+ also didn't complain. Don't know why I didn't try this earlier... But thanks for your suggestions @smowton . Closing this.