What does <fork>true</fork> means in pom.xml while using maven?
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.
Related videos on Youtube
sofs1
Updated on September 16, 2022Comments
-
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.
-
StackFlowed over 7 years
-
David Tonhofer over 6 years@StackFlowed How the heck does one get to that page from the Maven Compiler Plugin documentation at maven.apache.org/plugins/maven-compiler-plugin/index.html ?
-
Prashant over 6 years@DavidTonhofer this is for the Plugin sites always the same, click on "Goals" in the menu and then select the actual goal (
compiler:compile
) you want more details.
-
-
sofs1 over 7 yearsSo 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 over 7 yearsI think it starts any Java executable it finds on the PATH first if you do not use toolchain or <executable> settings.
-
sofs1 over 7 yearsYes, There is a <executable> in my pom.xml as well and it refers to 1.6
-
Ahatius over 7 yearsWow, 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.