# Maven plugin not using proxy?

**URL:** <https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101>\
**Category:** SonarQube Cloud\
**Tags:** proxy, maven\
**Created:** [May 11, 2021, 1:30pm UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101 "2021-05-11T13:30:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMCP](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BMCP](https://community.sonarsource.com/u/BMCP)\
**Post date:** [May 11, 2021, 1:30pm UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/1 "2021-05-11T13:30:27Z")

</div>

- 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](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops).

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?

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [May 17, 2021, 11:59am UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/4 "2021-05-17T11:59:13Z")

</div>

Hi @BMCP , could you please share how did you configured `MAVEN_OPTS`? Have you tried something like ([docs](https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-maven/)):

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

```

Please also take a look at [this topic](https://community.sonarsource.com/t/error-in-run-code-analysis-with-coporate-proxy/9241) and tell us if you still can’t solve the problem (there is an approach with `SONAR_SCANNER_OPTS` there).

---

<div class="post-metadata">

**Author:** ![BMCP](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BMCP](https://community.sonarsource.com/u/BMCP)\
**Post date:** [May 18, 2021, 7:09am UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/5 "2021-05-18T07:09:08Z")

</div>

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](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud) are working with these variables.

And for the maven settings, I’ve used the following [docs](https://maven.apache.org/guides/mini/guide-proxies.html).

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [May 18, 2021, 2:57pm UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/6 "2021-05-18T14:57:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BMCP](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BMCP](https://community.sonarsource.com/u/BMCP)\
**Post date:** [May 19, 2021, 7:12am UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/7 "2021-05-19T07:12:05Z")

</div>

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](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/4/c40e9612e15ceeb4fd5d20d1b6148903d211062a.png)

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](https://community.sonarsource.com/uploads/short-url/grdPejhraDOFHZCjnSL1eHjiOBP.txt) (26.6 KB)

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

---

<div class="post-metadata">

**Author:** ![Alexandre\_Holzhey](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_holzhey/32/74760_2.png) [@Alexandre\_Holzhey](https://community.sonarsource.com/u/Alexandre_Holzhey)\
**Post date:** [May 20, 2021, 7:03am UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/8 "2021-05-20T07:03:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BMCP](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BMCP](https://community.sonarsource.com/u/BMCP)\
**Post date:** [May 20, 2021, 8:36am UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/9 "2021-05-20T08:36:08Z")

</div>

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.

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/3/c39264057e7214f926c31eb1d1bdddc66a1f7b07.png)

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.

---

<div class="post-metadata">

**Author:** ![BMCP](https://avatars.discourse-cdn.com/v4/letter/b/a183cd/32.png) [@BMCP](https://community.sonarsource.com/u/BMCP)\
**Post date:** [May 25, 2021, 12:28pm UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/10 "2021-05-25T12:28:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [November 26, 2021, 1:39pm UTC](https://community.sonarsource.com/t/maven-plugin-not-using-proxy/43101/12 "2021-11-26T13:39:47Z")

</div>

Closed on November 26, 2021, 1:39pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
