What does <fork>true</fork> means in pom.xml while using maven?

11,402

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.

Share:
11,402

Related videos on Youtube

sofs1
Author by

sofs1

Updated on September 16, 2022

Comments

  • sofs1
    sofs1 over 1 year

    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.

  • sofs1
    sofs1 over 7 years
    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?
  • Prashant
    Prashant over 7 years
    I think it starts any Java executable it finds on the PATH first if you do not use toolchain or <executable> settings.
  • sofs1
    sofs1 over 7 years
    Yes, There is a <executable> in my pom.xml as well and it refers to 1.6
  • Ahatius
    Ahatius over 7 years
    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.