Issues with scanner options in ADO tasks

Template for a good new topic, formatted with Markdown:

  • ALM used: ADO

  • CI system used: Azure DevOps

  • Scanner command used when applicable SonarCLoudPrepare@2

  • Languages of the repository: mixed

  • Steps to reproduce

Scanning the codebase hits the same old Java Ruby errors:

##[error]12:38:46.154 ERROR [stderr] 2024-06-11T12:38:46.120Z [main] WARN FilenoUtil : Native subprocess control requires open access to the JDK IO subsystem

12:38:46.155 ERROR [stderr] Pass ‘–add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED’ to enable.

But how is this passed in ADO?

I have tried an extraProperties field:

cliProjectName: *blah*
cliSources: '.'
cliVersion: '6.0.0.4432'
extraProperties: |
  sonar.scanner.opts='--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED'

That didn’t work. Forcing an env variable into it doesn’t work:

  • task: Bash@3
    displayName: ‘Set env vars’
  • inputs:
    targetType: ‘inline’
    script: |
    set -e
    export SONAR_SCANNER_OPTS=‘–add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED’

What am I missing?

Hey there.

I think you have to set the SONAR_SCANNER_OPTS variable at the pipeline level, rather than the task.

What does that actually mean? It’s an ADO Task. I can understand the GitHub actions stuff, but that’s not relevant,

You can set pipeline variables in Azure DevOps as documented here.

Yeah, still not having any effect:

variables:
  SONAR_SCANNER_OPTS: '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED'
pool:
  vmImage: ubuntu-latest

14:55:16.981 INFO SONAR_SCANNER_OPTS=–add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED

14:58:30.351 ERROR [stderr] 	at org.sonar.scanner.bootstrap.ScannerMain.main(ScannerMain.java:38)
##[error]14:58:30.355 ERROR [stderr] 2024-06-12T14:58:30.309Z [main] WARN FilenoUtil : Native subprocess control requires open access to the JDK IO subsystem
14:58:30.355 ERROR [stderr] Pass '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED' to enable.

I also tried sticking in an env variable with Bash

Last shot before I shoot this over to our devs – can you try the JDK_JAVA_OPTIONS environment variable?

So on the newer version (6) it says to use SONAR_SCANNER_JAVA_OPTS, and when I put that in as an extra property , it complains that it isn’t java:

##[error]12:23:04.870 ERROR [stderr] Error: Could not find or load main class '–add-opens

Where does it say that? v6 is new, I hope I didn’t miss a memo. :laughing:

Seems like an issue with spaces. Wrapping in quotation marks might help.

SonarScanner CLI & SonarCloud (sonarsource.com)

Although in here, there seems to be a mix of unix quotes and curly quotes: [SonarScanner CLI & SonarCloud (sonarsource.com)]Analysis Parameters & SonarCloud

##[error]10:34:37.029 ERROR [stderr] Error: Could not find or load main class "–add-opens

This is with double quotes

    cliVersion: '6.0.0.4432'
    extraProperties: |
      sonar.scanner.javaOpts="--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED"
      sonar.sourceEncoding=UTF-8
      sonar.exclusions=**/*appsettings*.json

Hey!

Thanks. This new parameter was news to me.

It looks like we have a bug, and didn’t account for java options that look like this.

You can probably revert to v1 of the tasks (or set the version in v2 to 5.0.1.3006), and then be able to use SONAR_SCANNER_OPTS again. I’ll flag this for attention.

This has worked for me:

variables:
  SONAR_SCANNER_OPTS: '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED'

steps:
- task: SonarCloudPrepare@2
  inputs:
    SonarCloud: 'MySCLink'
    organization: 'org'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'key'
    cliProjectName: 'prod'
    cliSources: '.'
    cliVersion: '5.0.1.3006'

1 Like