1
votes

I am using a computer with Windows 7, and I have Hudson installed on it. I have had this installation for a while, and it has been working fine up till now.

Something has changed. Now, whenever I try to build a project, after successfully checking out the project from SVN, it fails with this message:

ERROR: M2_HOME is set to an invalid directory.
M2_HOME = "C:\Build\Hudson\.hudson\jobs\Score_Plugin\workspace\.."
Please set the M2_HOME variable in your environment to match the
location of the Maven installation

I cannot figure out why it is giving me this error. Why is Hudson trying to find M2_HOME in its own workspace? I tried the following, which seems to say that my Maven installation in my environment is just fine:

1. I opened up a CMD and typed in `where mvn` and got the following:

C:\Build\Maven\apache-maven-3.0.5\bin\mvn
C:\Build\Maven\apache-maven-3.0.5\bin\mvn

2. I typed in `mvn -version` and got this:

Apache Maven 3.0.5 <r01de14724cdef164cd33c7c82fe155faf9602da; 2013-02-19 05:51:28-0800>
Maven home: C:\Build\Maven\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Build\Java\jdk1.7.0_25_x64\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

3. I checked to see, and I have a `MAVEN_HOME` environment variable set to `C:\Build\Maven\apache-maven-3.0.5`.
I also have `%MAVEN_HOME%\bin` in my path.

It looks like my environment is working.

4. In an attempt to solve this error, I created a M2_HOME environment variable and set it equal to %MAVEN_HOME%.

5. To top it all off, I've rebooted my machine.

I'm still getting this error. I'm getting it for every project I try to build in Hudson. I'm not sure what I else I can do. Any ideas?

3
Have you changed the configuration of your hudson job to Use private Maven repository = true? The documentation for that option says When this option is checked, Hudson will tell Maven to use $WORKSPACE/.repository as the local Maven repository. Its seems feasible that hudson might do this overwriting the value of M2_HOME similar to as you are seeing.sbk
@sbk This is really weird -- I checked out that option, but it wasn't selected. I then selected it just to see what would happen, and now my build works!James Dunn

3 Answers

2
votes

My understanding is that %M2_HOME% is the home of the local Maven repository as opposed to %MAVEN_HOME% which is the Maven installation directory.

From memory, I think the local Maven repository on Windows is in C:\Documents and Settings\User\.m2\ but I've been Linux through-and-through for a few years now so I may be wrong.

Check for this local repository folder and try setting the variable to there instead.

1
votes

I am not sure why this worked, but it did.

As suggested by sbk's comment, I went to the build configuration. I clicked "advanced" to look for the `Use private Maven repository` option.

Hudson Build Maven Options

I expected to see this option selected as it would explain the problem. But it wasn't. I didn't expect it would help, but I selected the option anyway just to see what would happen:

Use Private Maven Repository

Amazingly, it worked! My project builds again in Hudson. I still don't know what caused this problem in the first place, or why this fixed it, but since it did this is the answer for me unless someone else can explain why this worked.

0
votes

I was getting same error. Earlier my directory was C:\apache-maven-3.0.4\apache-maven-3.0.4\bin I renamed the folder structure as C:\maven\apache-maven-3.0.4\bin Also updated the system variable accordingly