16

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
  • 21,611
  • 40
  • 152
  • 243

1 Answers1

13

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.

Ryan Gross
  • 6,423
  • 2
  • 32
  • 44
  • 4
    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 ? – lisak Jul 26 '11 at 16:22
  • 1
    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. – Ryan Gross Jul 26 '11 at 16:27
  • 1
    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 Jul 26 '11 at 16:29
  • by "clean" you mean "mvn clean" right ? not eclipse project clean – lisak Jul 26 '11 at 16:32
  • 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. – Ryan Gross Jul 26 '11 at 17:05
  • 3
    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 – lisak Jul 26 '11 at 17:12
  • What do you mean by just the Console? – Ryan Gross Jul 26 '11 at 17:20
  • @lisak let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1849/discussion-between-ryan-gross-and-lisak) – Ryan Gross Jul 26 '11 at 17:20
  • 2
    In the last release of m2e plugin the voice menu `Preferences > Maven > Goals` doesn't exist any more, is there any other solution? – landal79 May 17 '13 at 13:37
  • The maven builder is also run on every incremental build. This makes it very slow. – T3rm1 Apr 18 '18 at 14:04
  • 1
    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? – Simon Dec 06 '18 at 10:36