Merging AEM projects for deployment using Cloud Manager

Explore how multiple projects can be merged to into a single project for deployment to AEM as a Cloud Service using Cloud Manager.

Hello everyone, my name is Varun Mitra. And welcome to the video. In this particular lesson, we are going to merge two different Git repositories together.
After completing this training, you will be able to use multiple Git repositories.
Customers may have spread their code across multiple repositories. So as a part of migration to Cloud Manager, these repositories should be consolidated. We will implement this consolidation with the help of a two-step approach. Step one is where we move these projects files to a reasonable project structure base. And step two, is where we look at the Git commands to consolidate everything into a single Git repository. Let’s look at a typical project structure. Here you have your parent pom file, and you have sub projects like core, ui.apps, et cetera.
A key aspect over here is the presence of dispatcher configuration files within the code base.
Now, let’s go ahead and consolidate the code base into a new project folder call this projectA. Here the parent pom will be modified to include projectA, this is a simple move operation.
Since dispatcher configurations are available to our projects, as such, it makes sense to move them out of the projectA and move them to the top level. Now let’s add in projectB, that has been modified in the same manner as projectA. And also add in third project that is projectC. The parent is modified to include both projectB and C.
Now projectC has its own set of dispatcher configuration. These could include new rewrite rule, filter definition, et cetera. And these should be merged in with the dispatcher configuration already present at the root level.
This has to be done manually and the exact steps will differ from project to project. So, this is how you can consolidate your code base. Now let’s look at the Git command that will help you in setting up a consolidated Git repository. Let’s start with projectA. So here we have projectA with the same structure as we saw earlier. We are now going to clone this project into a Git repository using git clone command.
Next, we are going to restructure projectA by creating a new project folder, and moving everything apart from dispatcher configuration underneath the new folder. We will create a new pom.xml and add the pom.xml to Git and finally commit projectA to our Git repository.
We are going to follow the exact same steps for setting up projectB and commit projectB to our Git repository.
Now, we are going to merge projectA and B together and consolidate our Git repositories. First, we will checkout the master branch that is pointing to projectA, and then merge projectB into the master branch using allow-unrelated-histories flag. This flag allows two branches with completely different histories to be merged together. Once we have this consolidated project, we can easily push it to a Cloud Manager Git repository.
Now, let’s just quickly go ahead and merge multiple Git repositories and push them to a Cloud Manager GitHub.
So now let’s see how easily you can merge two different projects together. So, what I have over here is the clone of the WKND Site, I’ve simply cloned the AAM guides WKND, and pushed it to my own GitHub. I’ve done the same thing to my WKND_Event Site and pushed it to my GitHub as well. Now I’m going to simply restructure this WKND Site that is hosted within my own GitHub, so that it fits into the Cloud Manager project structure. Once that is done, I will merge it with my AEM WKND event Site, and this will allow me to have a consolidated Git repository containing two different projects. Once the projects are consolidated together, they could be pushed on to their own separate Git repository, or could be pushed to the Cloud Manager GitHub. So, this is my WKND Site. I have cloned it over here, onto my file system. Let me open up my command prompt. The first thing that I’m going to do is I’m going to simply go ahead and create a new directory over here. This directory will be used for storing or moving all of my sub projects.
I’m going to create a directory called as wknd, and I’m going to use the git mv command to move all of my sub projects into this particular directory. We quickly execute the following command. This will move my pom.xml, my all project core it.launcher it.test et cetera into the wknd folder. Once this is done you can verify the project structure. What I haven’t done is move the dispatcher configuration as they are supposed to be stored at the root level. Next thing that we are going to do is we are going to create a new pom.xml file. I have the newly generated pom.xml file right over here. This pom.xml file contains the wknd and the dispatcher module. Let me quickly go ahead and store it within the wknd folder.
And we quickly go ahead and save this particular file within my wknd directory or within my WKND GitHub project, and store my pom.xml file over here. A copy of this pom.xml file is available to you in the white paper that is provided alongside this video.
Now, with this done, I have a proper Maven Project Setup in here. The next thing which I’m going to do is I’m going to add this particular pom.xml file to my Git. That is, I will simply run, git add pom.xml.
This will allow me to add this particular pom.xml to my Git project, as such Git will be able to keep a track of it. Next thing, I’m going to commit all of these new changes. Since there are quite a few changes involving moving of certain folders, adding a pom.xml, as such, I need to perform a git commit. And I will provide a new tag over here.
And this should allow me to commit all of these changes to make it.
Once this command finishes execution, I will be able to push these changes to my GitHub by using the git push command.
All of the changes are listed out over here, I’m going to use the git push command with the force parameter to push this to my master branch.
So, this seems to be successful. Now I can go back to my WKND Site, do a quick refresh. And I should see the changes take effect over here. Now what I did earlier was that I also modified the WKND_Event Sites. Let me quickly go back to my repositories.
So, I did the same thing with my WKND_Events Site and I put it in the suitable format. Now the next thing that we are going to do is we are going to simply combine this newly created WKND Site and WKND_Event Site together into a single consolidated project. So, let’s just go ahead and do that. The first step to do that is to identify the parent project where this merge is going to happen. That is, you need to identify into which project you are going to merge your consolidated code base. For me, that project happens to be WKND. I’m going to merge the WKND_Event Site into my WKNDS project.
First thing that I will do is I will checkout my current master, or my current master branch, so that my branch pointer points correctly. Next thing which I’m going to do is I’m going to add the WKND_Event as a remote branch. I can grab the URL directly by going here, and I can add it in pretty easily. So, I will use the following command that is git remote add, And I will provide a tag over here that is WKND-EVENTS.
And then I will quickly add the following …
URL. This will allow me to add the WKND_Event as a remote repository. Now I’m going to fetch the WKND_Events using the identifier that I provided earlier.
This will allow me to fetch the WKND_Events Site.
Next thing I’m going to perform a simple checkout over here.
That is do something like git checkout b and provide the exact name over here.
Once this command finishes, I will have a new branch or my GitHub will switch to a new branch. I’m going to now quickly go ahead and checkout the directory structure in here. As you can see, the directory structure reflects the WWKND_Events or the WKND_Events project. Even though I’m in the WKND Site right now since I checked out or since I’m on a different branch, I’m able to see the WKND_Events Site over here. I’m going to quickly go ahead and checkout the master project, that still points to my WKND site. Once this is done, I will be able to merge these two together.
Now with this done, I can execute the following command that is, git merge WKND-EVENTS And then I will use allow-unrelated-histories flag over here.
Unrelated-histories-flag will allow me to merge together these two unrelated branches. Since both of these branches have unrelated histories which have no relation whatsoever to each other, as such, I would be able to merge them two with the help of this particular flag.
Without this flag, the merge operation will fail as it would report different conflicts. So, you can see that I’m able to merge them two successfully over here, I can also do a dir at that point and verify that both my WKND_Events and WKND folders are present at the same location. Now the important thing to do over here is to modify the pom.xml file. By modifying this pom.xml file, we would be able to merge these two projects together successfully. Without a modified pom.xml file, your Maven project cannot compile successfully. So, I have the modified pom.xml file right over here. I’m going to quickly go ahead and save it in the correct folder.
I will go to the WKND Site and replace the pom.xml with this pom.xml file.
And with this done, my pom.xml file has been modified. And now I can simply go ahead and perform a git commit.
If you want, you can also do with a maven verify to verify your project structure. But at this point, I’m going to simply go ahead and push this to my Cloud Manager GitHub. Let me quickly find out my repository name. I’ve already set up a repository for demonstration purposes, which is this particular one, I’m going to quickly go ahead and push this to this particular Git repository. I’m going to add it as a remote branch, provide the Git URL, and then simply do a git push.
And this is how you can consolidate two different projects together and push them to your GitHub. So, as we saw, we are able to do that quite easily using different Git commands. All of these Git commands are available to you in the white paper that is provided alongside this video. So now you should be able to utilize multiple Git repositories. Thank you very much for watching this video and have a great day. -