Maven plugin not using proxy?

  • ALM used: Azure DevOps
  • CI system used: Azure Devops
  • Scanner command used when applicable: C:\WINDOWS\system32\cmd.exe /D /S /C ““C:\Program Files (x86)\apache-maven-3.6.3\bin\mvn.cmd” -f C:\agent\5\12\s\pom.xml package org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar”
  • Languages of the repository: Java

We are using Azure DevOps with On-Premise agents which runs behind a company proxy.

For almost all tasks and plugins, the proxy is bein used, but when we run SonarCloud analysis as a maven plugin, it is not using the proxy. The only way to make the maven plugin use the proxy, is adding the proxy settings as maven options to the maven task: Maven build and release task - Azure Pipelines | Microsoft Docs.

The disadvantage is that the settings need to be entered for every build that runs SonarCloud from Maven.

I tried the following options, but none of them seem to work:

  • As part of JAVA_OPTS environment variable
  • As part of MAVEN_OPTS environment variable
  • As part of SONAR_SCANNER_OPTS environment variable
  • As part of the maven settings.xml (in mavens conf folder)
  • As part of the users maven settings (in users .m2 folder)

Am I missing something, or is this a bug in the maven plugin?

Hi @BMCP , could you please share how did you configured MAVEN_OPTS? Have you tried something like (docs):

set MAVEN_OPTS=-Dhttp.proxyUser=user -Dhttp.proxyHost=host -Dhttp.proxyPassword=password

Please also take a look at this topic and tell us if you still can’t solve the problem (there is an approach with SONAR_SCANNER_OPTS there).

Hi @Alexandre_Holzhey, thanks for your response. I’ve configured it like this:

MAVEN_OPTS=-Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080 -Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080

JAVA_OPTS and SONAR_SCANNER_OPTS are configured with the same values.

The “default” SonarCloud tasks are working with these variables.

And for the maven settings, I’ve used the following docs.

Thanks for the information. I will try to reproduce it here, meanwhile could you share the logs that tell you that sonarcloud is not reacheable?

While I was checking my logfiles for secrets I think I found my problem. I found out that my proxy settings in the MAVEN_OPTS environment variables were missing:

env.JAVA_OPTS=-Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080 -Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080,
env.SONAR_SCANNER_OPTS=-Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080 -Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080,
env.MAVEN_OPTS=-Xmx1024m

If I remove this setting from the build task, it can connect:
image

This option is set by default in the task when you add the task in an Azure DevOps pipeline, and by default you don’t see the value because that part is collapsed.

Although I would expect that the JAVA_OPTS and/or SONAR_SCANNER_OPTS should be enough.

Here is a part of the logfile:
PartOfLog.txt (26.6 KB)

If you need more, is there a way I can send the logfile in private?

Hi @BMCP , thanks for the information. The log part you provided is fine. I would ask you to instead of removing the setting, setup the proxy configuration for MAVEN_OPTS like you did for JAVA_OPTS and SONAR_SCANNER_OPTS, resulting into something like this:

env.JAVA_OPTS=-Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080 -Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080
env.SONAR_SCANNER_OPTS=-Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080 -Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080
env.MAVEN_OPTS=-Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=8080 -Dhttp.proxyHost=my.proxy.host -Dhttp.proxyPort=8080

If this works, then remove the proxy settings from SONAR_SCANNER_OPTS and check if it still works. I want to understand better what is your problem trying to isolate it. Could you do that and tell us the results, please?

Hi @Alexandre_Holzhey,

If I enter the same proxy settings in the Azure DevOps task, then it is running fine. But then every user in our organization that is using maven builds, have to add those settings to their build task.

To clarify, on the build agents, the MAVEN_OPTS environment variables do include those proxy settings, like the JAVA_OPTS and SONAR_SCANNER_OPTS . But the Maven build task in Azure DevOps contains the “-Xmx1024m” in “Set MAVEN_OPTS to” by default. So the MAVEN_OPTS environment variable on our build agent always gets overwritten by the Maven build task, or we have to clear that value for every build with maven.

So on the machine, the MAVEN_OPTS is configured like I did for JAVA_OPTS and SONAR_SCANNER_OPTS.

I also tried out you suggestion.

I removed the Set MAVEN_OPT to variable from the task, so the environment variables for MAVEN_OPTS with the same configuration as JAVA_OPTS is used. And I removed the SONAR_SCANNER_OPTS. Then the task is running fine.