Skip to main content

AEM Project Maven Build - Easy setup and steps to run commands via command line

We generally run maven commands every day to deploy the bundles or any other changes in the project to AEM server.

There are a lot of options to sync them automatically like using Brackets or AEM Server plugin configurations in IDE's etc.. These are very faster for deployments and changes to be reflected in AEM server

In case if you would like to do a complete build, we can run the same from Eclipse by using the run commands or via command prompt using the complete maven command but IDE's generally occupy lot of memory and might slow down sometimes.

I generally use Command prompt for the builds. I generally navigate to the repo folder and type the maven command "mvn clean install -PautoInstallPackage,adobe-public"

Note: adobe-public can be ignored if you already set the repo in the maven settings

I work on different projects and repositories every day and navigating to different folders and typing the same command (You can always copy and paste the command from a clipboard or notes - but you have to navigate b/w windows and multiple operations). To have a faster execution I tried using the batch scripts and worked very well. Hope this will be your use case too and might be useful.


Set Up:

  • Create a new folder "batch" in any directory. 
  • Create a new batch file lets say mvnc.bat
  • Copy the below snippet in your batch file and save it

cd C:\repository\common-repo-folder
echo Running build for Common code
mvn clean install -PautoInstallPackage

Now navigate to the batch folder and just execute mvnc and it should execute the maven command for you for that specific code repository, but again in this case you have to navigate to the batch folder. To avoid that we can add the batch to the path variable in our environment variables.


Add the batch folder to the path variable and save the changes

You can find different ways to add path variables based on your environment in below URL:


Once the path variable is set, you can run the command anywhere in the command prompt.

In my scenario we use Findbugs, if you would like to skip tests you can pass an argument while running the script.

Use the below script in the bat file.

@echo off

echo Switching to directory C:\repository\common-repo-folder

cd C:\repository\common-repo-folder

set skip=%1

set skipTests=

if "%skip%" == "skip" (
  set skipTests=-Dfindbugs.skip=true
  echo Skipping findbugs
)

echo Running build for Commons code Command: mvn clean install -PautoInstallPackage %skipTests%

mvn clean install -PautoInstallPackage %skipTests%


For Shell Scripts (to execute in Mac Terminal) use below Script:


echo Switching to directory /c/repository/common-rep-folder
cd /c/repository/common-rep-folder


skipTests=
if [ "$1" = "skip" ]
then 
 skipTests=-Dfindbugs.skip=true
 echo Skipping findbugs
fi

echo Running build for Commons code Command: mvn clean install -PautoInstallPackage $skipTests

mvn clean install -PautoInstallPackage $skipTests


Note: Change the path in the first line to your local path

Now run the command as "mvnc skip"

In the above command"skip" is an argument which is passed to your batch script to skip the tests. You can use your own argument and update the script accordingly

In the similar fashion create different batch scripts for different repositories and use simple commands to run the build.


Few samples:
mvnc --> runs the build for common code
mvnp --> runs the build for Project code
mvnp2 --> runs the build for project code

Commands are nothing but your batch file names.

Note: There is no restriction in the folder and file names. you can use your preferred naming conventions.

Shorter version of the setup in just 2 steps :) 


  • Create a batch folder and add it to the path variable 
  • Create a new mvnc.bat folder and add the below script and change the path in the first line to your local path
@echo off

echo Switching to directory C:\repository\common-repo-folder

cd C:\repository\common-repo-folder

set skip=%1

set skipTests=

if "%skip%" == "skip" (
  set skipTests=-Dfindbugs.skip=true
  echo Skipping findbugs
)

echo Running build for Commons code Command: mvn clean install -PautoInstallPackage %skipTests%

mvn clean install -PautoInstallPackage %skipTests%

That's it, you are all set to use your short commands


You can add more steps like checking the branch name or status and pull the latest code every time before running the build like 

git branch
git pull









Comments

Popular posts from this blog

Delete DAM Asset using Workflow

This article shows you to create a simple workflow process step and use it for deleting an DAM Asset. You can ask me why do I need a workflow when I can delete it directly using the delete button :) The intention is to validate the asset information before deleting the asset or trigger any other workflow for the asset and do manipulations like updating the asset data to an user before the deletion as you will not be able to get that post deletion. you can catch the events in the Event Listeners, but there will be no data by then. Simple Workflow Process Step Create a workflow process step by using the below example package com.flash.aem.core.workflow; import java.util.HashMap; import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.osgi.

Groovy Console Integration and executing scripts in AEM

Steps to install Groovy in AEM. Below Github have the steps to install the latest Groovy console https://github.com/icfnext/aem-groovy-console You can also navigate to the releases section and download the required package. https://github.com/icfnext/aem-groovy-console/releases I have used 12.0.0 version for this demo. Download the Groovy Package ( Direct link to the package  ) Upload the package to AEM via Package manager  http://localhost:4502/crx/packmgr/index.jsp Once the package is installed, you should be able to access the groovy console  http://localhost:4502/etc/groovyconsole.html Note: From 13.0.0 release, the paths were changed from /etc/ to /apps/ to access Groovy Console Sample Groovy Scripts: Printing a simple String println 'Hello World'; Click on Run Script Displays Hello World in the Console Get a Page Object final def page = getPage('/content/aem-flash') println 'page path is: ' + page.path; Re