14

I am using maven 3.3.3. and I have <fork>true</fork>. I ran into issues(MojoException) and fixed it by commenting out

 <fork>true</fork>
 <compilerVersion>${java.version}</compilerVersion>

My project was using Java 1.6 and java.version in above line refers to 1.6, but my computer environment variables was 1.7 and maven 3.3.3 needs Java 1.7 . Now my issues are fixed.

But I am not able to understand 1) what does fork mean here? 2) What does it do? 3) Having it set to true or false, what changes it?

I went through the documentation, but it is hard to follow. Thanks.

4

1 Answer 1

13

true means it will create (fork) a new JVM to run the compiler. This is a bit slower but the isolation is better.

Especially you can specify a different JVM than the one Maven is started with, and you can also specify command line parameters (for increasing Heapsize or Metaspace) only in this case. In your case it causes problems as it seem to use the wrong JVM, you could specify the full path with <executable> or a toolchain configuration.

This is one method to use a modern Maven which does not run with Java 1.6, but still use a clean compile environment for older source/target versions.

false means it is startign the compiler directly in the JVM you have run maven with, this makes the build less repeatable.

4
  • So in my case since my project (that is, in pom.xml java.version is set as 1.6), but maven is 3.3.3. and setting fork=true, starts a new jvm 7 and tries to execute 1.6 code in it. Am I right?
    – sofs1
    Commented Dec 21, 2016 at 19:28
  • I think it starts any Java executable it finds on the PATH first if you do not use toolchain or <executable> settings.
    – eckes
    Commented Dec 21, 2016 at 19:30
  • Yes, There is a <executable> in my pom.xml as well and it refers to 1.6
    – sofs1
    Commented Dec 21, 2016 at 19:30
  • 2
    Wow, what a coincidence. I was just looking for a way to get IntelliJ to build my Java 6 maven project, while using Maven 3.3.9. Gonna try that.
    – Ahatius
    Commented Dec 21, 2016 at 19:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.