Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obsolete Maven environment variable M2_HOME is set on Ubuntu which can cause problems #2534

Closed
1 of 7 tasks
famod opened this issue Jan 24, 2021 · 14 comments
Closed
1 of 7 tasks
Assignees
Labels
bug Something isn't working OS: Ubuntu

Comments

@famod
Copy link

famod commented Jan 24, 2021

Description
Since Maven 3.5.0, environment variable M2_HOME is not used/supported anymore:
https://maven.apache.org/docs/3.5.0/release-notes.html#overview-about-the-changes

Based on problems in using M2_HOME related to different Maven versions installed and to simplify things, the usage of M2_HOME has been removed and is not supported any more MNG-5823, MNG-5836, MNG-5607.

But still, M2_HOME=/usr/share/apache-maven-3.6.3 is set on ubuntu-latest (18.04 in my case).

This causes a very nasty side effect when using stCarolas/setup-maven:

    - name: Set up Maven
      uses: stCarolas/setup-maven@v4
      with:
        maven-version: 3.3.9

which is extending PATH, but is not unsetting or modifying M2_HOME (which is correct IMO).
If you then run mvn --version, you will be faced with 3.6.3 instead of 3.3.9 although the right one (3.3.9) is on the PATH, as can be verified with which mvn.
Now comes the "fun part": Since the mvn script in 3.3.9 still supports M2_HOME, it will use /usr/share/apache-maven-3.6.3, eventually executing 3.6.3. instead of 3.3.9. 🤦

Area for Triage:
Java

Question, Bug, or Feature?:
Bug

Virtual environments affected

  • Ubuntu 16.04
  • Ubuntu 18.04
  • Ubuntu 20.04
  • macOS 10.15
  • macOS 11.0
  • Windows Server 2016 R2
  • Windows Server 2019

I have only checked ubuntu-latest but I suppose it affects all environments!

Expected behavior
Obsolete M2_HOME variable is not set.

Actual behavior
Obsolete M2_HOME variable is set causing nasty side effects in case Maven older that 3.5.0 shall be used.

Repro steps
None yet. Let me know if you really need a reproducer.

Workarounds

    - name: set environment variables
      uses: allenevans/set-env@v2.0.1
      with:
        M2_HOME:

or call unset M2_HOME in the same step you are calling mvn.

@famod
Copy link
Author

famod commented Jan 24, 2021

Now, just dropping it without a replacement might break some actions etc.
AFAICS, https://github.com/actions/setup-java seems to be using it somewhere.
So it might be a good idea to offer an alternative, e.g. MAVEN_HOME but then again this is used internally in the scripts of newer Maven versions so it might not be a good idea either...

@andy-mishechkin andy-mishechkin added OS: Ubuntu investigate Collect additional information, like space on disk, other tool incompatibilities etc. bug Something isn't working and removed needs triage investigate Collect additional information, like space on disk, other tool incompatibilities etc. labels Jan 25, 2021
@dsame dsame self-assigned this Jan 26, 2021
@dsame
Copy link
Contributor

dsame commented Jan 28, 2021

We can remove M2_HOME safely because it currently points to maven 3.6.3 which does not use M2_HOME in any way.
The users builds that use maven of the versions older than 3.5.0 definitely have M2_HOME set in their pipelines pointed to the desired location.

M2_HOME still may be referenced some user's scripts for some purposes it is not intended to be used for. The probability of such use is minimal and much less than the probability of the problems caused by M2_HOME presence.

We have a choice either to remove M2_HOME right now formally following maven's status or to announce the deprecation and remove it in a next releases.

@miketimofeev ?

@AlenaSviridenko
Copy link
Contributor

Both AzDO tasks https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/MavenV2 and https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/MavenV3 use this variable. So we should be very careful with its removal

@dsame
Copy link
Contributor

dsame commented Jan 29, 2021

@AlenaSviridenko maven tasks set the value of the variable, they do not read the value.

Moreover the semantic of the variable is "To instruct the maven start script where to find its home directory", it is not intended to be used in the manner "get its value for your own purposes"

@maxim-lobanov
Copy link
Contributor

@dsame , @AlenaSviridenko , actually, M2_HOME is used for "read" in Maven ADO tasks: https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/MavenV3/maventask.ts#L69
But as I can see, task has fallback strategy to find mvn in PATH. It should work for us.
I suggest to double check with @egor-bryzgalov @anatolybolshakov

But in general, I agree with @dsame. Variable can be removed but required announcement

@maxim-lobanov
Copy link
Contributor

I think we should also check other images and do that consistently (M2_HOME is available on Windows too).

@egor-bryzgalov
Copy link
Contributor

We have no concerns about removing this variable in case if PATH would be set correctly but it makes sense to announce this prior to removing it since the variable could be used by some other tasks or scripts.

@maxim-lobanov
Copy link
Contributor

The new Ubuntu images without the variable have been deployed. Also we are going to remove it from Windows images. It can be tracked in #2600

@saikirangit
Copy link

This is breaking all our builds with error and we use setup-java... what is the workaround?

m2_home environment variable is not set

@maxim-lobanov
Copy link
Contributor

@saikirangit , see mitigation ways in #2600

@saikirangit
Copy link

@maxim-lobanov above solution did not work for me and still threw same error... I had to do this to get it working.

Not the cleanest way but I will convert this to use which mvn than hardcoding the value

- name: Set up Maven
  uses: stCarolas/setup-maven@v4
  with:
    maven-version: 3.6.3
    
- name: Set environment variables
  uses: allenevans/set-env@v2.0.1
  with:
    M2_HOME: /opt/hostedtoolcache/maven/3.6.3/x64

@famod
Copy link
Author

famod commented Feb 24, 2021

@saikirangit I'm wondering what exactly breaks in your builds. Since you're already using Maven 3.6.3 (which does not use M2_HOME anymore), it shouldn't be Maven itself causing the failures, right?

@saikirangit
Copy link

It could be probably because of setup-java. Most of the java based actions uses setup-java, it could be that action which is internally referring? But I see good number of projects in my organization that has this issue currently.

@famod
Copy link
Author

famod commented Feb 24, 2021

@saikirangit I don't have any problems with actions/setup-java@v1. In fact, I was now able to remove the unset M2_HOME workaround in gitflow-incremental-builder/gitflow-incremental-builder#317 (this project is also using setup-java).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS: Ubuntu
Projects
None yet
Development

No branches or pull requests

7 participants