How do Java and Maven builders work together in eclipse?

15,957

The main purpose of the Maven builder is to ensure the correctness of your POM file and pull down the dependencies that you need. It will go out and check for new dependencies if you save your POM file, and it will report errors when it cannot find dependencies.

Additionally, the maven builder will run a maven build up to the goal that you have set in Preferences -> Maven->Goal to run after updating project configuration after you do a Project->Clean... on your project from eclipse or make changes to the POM file and save it from within eclipse.

The Java Builder is still in charge of building the project and reporting compiler errors in the Problems view, for providing the input for the built in jUnit runner in eclipse, etc.

Share:
15,957
lisak
Author by

lisak

Github

Updated on June 05, 2022

Comments

  • lisak
    lisak about 2 years

    do I understand correctly, that Java builder recompiles sources on scr path to the output path, which usually happens after each "ctrl + s" if automatic building is activated or via "ctrl + b" or throws validation errors from javac.

    As to Maven2Bulder. I just cloned m2e-core git repository and there is the corresponding class org.eclipse.m2e.core.internal.builder.MavenBuilder, which is quite complicated stuff.

    <projectDescription>
        <name>modeshape-example-repositories</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments>
                </arguments>
            </buildCommand>
            <buildCommand>
                <name>org.eclipse.m2e.core.maven2Builder</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildSpec>
        <natures>
            <nature>org.eclipse.m2e.core.maven2Nature</nature>
            <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
    </projectDescription>
    

    I thought it gets pom.xml, m2eclipse variables about repo location and settings.xml or some profile information and goal/target of the current Run configuration and it just runs mvn with this pieces of information, but it does much much more and it can produce unexpected behavior.

    Btw, is it only used when a developer actually Run As > some maven goal ... ?

  • lisak
    lisak almost 13 years
    I don't see any option in Preferences > Maven as to the target when building. This means that when I save pom, build / clean project, MavenBuilder runs ? What about the java builder, it is supposed to run when ctrl + b isn't it? Or does it only run when I save a *.java file on src path ?
  • Ryan Gross
    Ryan Gross almost 13 years
    If you have build automatically turned on, then the java builder will build when you save a .java file. If not, then it will run when you press ctrl + b.
  • lisak
    lisak almost 13 years
    I'm talking about MavenBuilder, you said that "maven builder will run a maven build up to the target that you have set in Preferences -> Maven after you do a clean on your project"
  • lisak
    lisak almost 13 years
    by "clean" you mean "mvn clean" right ? not eclipse project clean
  • Ryan Gross
    Ryan Gross almost 13 years
    no... I meant eclipse clean... if you switch to the maven console after doing a clean, you will see the (abbreviated) output from the build.
  • lisak
    lisak almost 13 years
    I have is just the Console, and there is not output when doing eclipse project clean...only in a fraction of a second something happens in Progress view
  • Ryan Gross
    Ryan Gross almost 13 years
    What do you mean by just the Console?
  • Ryan Gross
    Ryan Gross almost 13 years
  • landal79
    landal79 about 11 years
    In the last release of m2e plugin the voice menu Preferences > Maven > Goals doesn't exist any more, is there any other solution?
  • T3rm1
    T3rm1 about 6 years
    The maven builder is also run on every incremental build. This makes it very slow.
  • Simon
    Simon over 5 years
    From the description above, my understanding is that the Maven Builder must always run +before+ the Java Builder, so that the latter runs using the most recent dependencies. Can someone confirm that the order of these two builders should be described, and that it matters?