Search code examples
javaeclipsemavenm2eclipse

Run Maven Build after Existing Maven Build in Eclipse


Say i have two Maven Build Configurations in Eclipse for Projects 'A' and 'B' where both of them are for two independent Projects

Is there a way using which i could execute Maven Build for Project 'B' after successful completion of Project 'A'?

I see options to add Parameters under 'A' Maven Build --> Main Tab but not sure how to use it.

Please let me know in case I am missing anything...

EDIT:

Adding description to my existing Problem statement Say i have below 3 projects

  1. Project Foo
  2. Project Bar
  3. Project Alpha
  4. Project Parent

Now, Alpha is my main EAR which contains both Foo and Bar.
Parent is our Parent Project

My Build versions are always by default 1(so no version issues)

I did few changes in in Project Bar, i want that if i execute Maven Build on Project Bar, Maven Build for Project Alpha should be auto triggered.

Just to add here, i wanna refrain my self for running Build on Parent Project

Thanks in Advance, Varun


Solution

  • If eclipse is not your concern and you just want to build your projects one after each other than one tricky way you can try by creating a batch which will build the projects.

    Take a look on below sample batch which I tried for myself,

    @ECHO OFF
    SET "CODEBASE=C:\project_workspace"
    SET "JAVA_HOME=C:\Java\1.7.0.25-x64"
    SET "MAVEN_HOME=C:\Maven\Maven3"            
    
    SET "PROJECTA_LOC=%CODEBASE%\ProjectA"
    SET "PROJECTB_LOC=%CODEBASE%\ProjectB"
    
    SET MVN_CMD=call mvn clean install -DskipTests -U
    
    REM -- Environment Details --
    ECHO CODEBASE: %CODEBASE%
    ECHO JAVA_HOME: %JAVA_HOME%
    ECHO MAVEN_HOME: %MAVEN_HOME%
    
    REM -- project location  --
    ECHO PROJECTA_LOC: %PROJECTA_LOC%
    ECHO PROJECTB_LOC: %PROJECTB_LOC%
    
    SET PATH=%PATH%;%JAVA_HOME%/bin;%MAVEN_HOME%/bin;
    ECHO %PATH%
    
    REM -- Calling Project A maven build
    CD %PROJECTA_LOC% 
    %MVN_CMD%
    
    REM -- Calling Project B maven build
    CD %PROJECTB_LOC% 
    %MVN_CMD%
    

    Hope it helps

    EDIT: Changed Project B's name in comment