Older default java version used with Azure devops Hosted agent

When using sonar cloud plugin for azure devops with a hosted agent (win 2019) Machine specs the default (1.8.0) java version is used. But other versions are also installed on the same agent (see machine specs)

The following warning is shown:

##[warning]WARN: The version of Java (1.8.0_222) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.

Would it be possible in the case of a hosted agent, that the proper version can be used?

1 Like

Hey there.

You should be able to adjust the JAVA_HOME pipeline variable to the path mentioned in the documentation you shared.

There could be other solutions – I’ll let others share. :slight_smile:

3 Likes

Or you can also add a task in your build pipeline like the one we have on our bunch of sample repos here :

https://dev.azure.com/sonarsource/DotNetTeam%20Project/_git/sample-dotnet-core-project?path=%2Fazure-pipelines.yml&version=GBmaster&line=18&lineEnd=18&lineStartColumn=1&lineEndColumn=21&lineStyle=plain

Mickaël

I think we’re going to need a better solution than using a hard-coded path to the JRE. That’s going to change “randomly” when MS updates the build agents - which would suddenly break builds. I know this isn’t entirely in your hands, but is there a way to suppress the warning for now? It’s decorating every PR build, and the ideal solution here is for MS to change the default version of the JRE.

2 Likes

This would be a workable solution if you have to maintain a couple of pipelines but in the case of 100+ pipelines then this is not the right solution. On the other hand, by doing this you now depend on a very specific build agent with the given path.

2 Likes

It would be better if sonarqube/sonarcloud scanner could use the a given java path or check if JAVA_HOME_11_X64 is set.

The warning itself is also weird in that the requirements of sonarqube scanner states that it is supported sonar qube requirements and that java 1.8 is still supported until december 2020. I do agree that it would be nice if this warning can be suppressed.

I don’t see why Microsoft should change the default on a supported Java version, it would be nice if we could choose the default java version. That is a different story, and I am also working on that on the Microsoft forums.

Same as Colin’s solution is that this would work if there are only a couple of pipelines to maintain, but if you need to maintain 100+ pipelines that you first need to add all those task and when Microsoft upgrade the java version, then the clean solution would be to delete all those tasks.

Hey there,

Same as Jacob, I have about a 100 pipelines that need to be altered if I were to go with either Colin or Chris’s solution. I think that a pipeline extension like SonarCloud’s shouldn’t be reliant on these kinds of work arounds for the most common scenario.

Also, I find posting a comment in a pull request somewhat intrusive for a message like this. But that is just my personal opinion and you can do with that what you will.

Kind regards,

Jeroen

1 Like

Hi,

Same here. Many build definitions from many teams. Would be great if we don’t have to update all of them (would feel weird for teams using MSBuild to have to add Java settings in their build definition).
My suggestion: Can SonarSource discuss this with Microsoft, and once Microsoft has updated their environments, then automatically upgrade the sonarscanner, and leave us users out of that discussion?

Kind regards,
Richard

1 Like

The problem with this solution is you are just swapping one warning for another.

You then get warnings about an illegal reflective access operation:

*Edit linked to the wrong thread

But what you link to here is just a regular warning right? Not a PR decoration comment like is the case with the issue described in the original post.

Please remove this warning. You are punishing users of a cloud service who have very little control over what is installed on the hosted build agents.

2 Likes

I’ve had to fix this for both linux & windows agents. In order to get it working I found I had to update PATH.
Windows:

echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)/bin;$(PATH)"

Linux:

echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME_11_X64"
echo "##vso[task.setvariable variable=PATH]$JAVA_HOME_11_X64/bin:$PATH"

In my opinion, the marketplace tasks provided by Sonar should automatically use the correct Java version. It is already installed on the image, so why can’t you just use it?

It should be the tasks responsibility to look for the correct version, not the users to point the task to the correct version.

Marketplace task: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud

Image software list: https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md

2 Likes

As i do agree that sonarcloud should fix this, I have also created a feature request on the Microsoft side for letting us choose what the default java version should be feature request choosing java version on hosted agend.

Also don’t forget sonarqube plugin: marketplace task for sonarqube.

1 Like

Even we are facing the same issue. As of now we have over 25 pipelines. Now for all the Pull Requests this is posted as an warning. Until an action is taken on this, it is stopping the developers from merging the code.

Even I believe that the SonarCloud Analysis task should be able to identify weather the required Java version is installed or not.

1 Like

Hello there,

Thank for your feedback. We will have a look on what we can do to improve this. The idea was to really warn the users, and we know that Hosted agent are still stuck on Java 8 by default. Here a summary post that explain the reasons : SonarCloud scanner environment soon to require Java 11+

The problem is that if we force Java 11 to be used, some of the users will not be able to build anymore their solution (like Xamarin) and that’s not what we want indeed. So we’ll need to find a solution that fit everybody’s need. Hope you’ll understand.

Mickaël

This worked for Windows image. What is the path to be set in Ubuntu image?

You can find a sample project for Ubuntu here. The path to the JDK is the following: /usr/lib/jvm/zulu-11-azure-amd64

3 Likes

The problem is that if we force Java 11 to be used, some of the users will not be able to build anymore their solution (like Xamarin) and that’s not what we want indeed. So we’ll need to find a solution that fit everybody’s need. Hope you’ll understand.

I am confused by this.

Seems like it would be possible for your task to search for known locations of the preferred Java version and if it finds it, use that.

This is exactly how several Microsoft tasks work. For example, the Nuget task. It searches known locations for the required version and uses it if found.

I am not seeing how doing this would impact other aspects of you build. You are simply specifying the Java version being used by your tasks. Other tasks can use any version of Java they like…

Unless I’m missing something?

In the short term, you really need to remove the comment that is added to every PR. It really messes up our workflow. We can no longer auto-complete PRs.

3 Likes