简体   繁体   中英

Merge two Java Maven projects into one

I am working on a Java/Maven project. I am using another project as a JAR library, everything is working fine.

My manager wants me to use only one Git repository. So he asked me to merge both the codes and make it a single project. What are the things I need to keep in mind.

Confused about how to do it and what are the things I need to keep in mind (like changes in pom.xml )

Things I have already tried:

  • Created new project and trying to copy the src part and paste into new projects src [doesn't seem correct]
  • Try to copy the whole project and paste into new one. [no idea if that will work]

Please help.

Thanks In advance.

My manager wants me to use only one Git repository. So he asked me to merge both the codes and make it a single project.

Basically placing two Maven based projects in one Git repository and producing one Maven project that will use both the original project and the external library are two different tasks. Since under Git repository you have a file system that can look like:

|__.git
|__my-project
|  |__ pom.xml
|  |__src // and source code inside
|__used-to-be-external-lib
   |__ pom.xml    
   |__src 

This would mean that projects share the same repository but are completely independent.

On the other hand if the goal is to build two projects together than consider using multi-module Maven project:

In this case you'll end up with something like:

|__.git
|__project
   |__pom.xml  // will have the packaging pom as you can read in link I provided
   |__my-project
   |  |__pom.xml
   |  |__src
   |__used-to-be-external-lib
      |__pom.xml 

The POM with packaging pom that I've mentioned in the second example will contain a list of modules:

<?xml version="1.0" encoding="UTF-8"?>
  <project...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>...</groupId>
  <artifactId>...</artifacId>
  <version>...</version>
  <packaging>pom</packaging>
  <modules>
    <module>my-project</module>
    <module>used-to-be-external-lib</module>
  </modules>
</project>  

Probably a crude way of doing it. let's assume that you have two maven projects A and B. Now create a new project C in your intllij-idea. In project C, create a new module A1. Copy the dependencies and build, properties (if present) from pom.xml of A to the pom.xml of A1. Now copy your src directory from project A to src of A1 and so the resources. Repeat the same process for your project B, ie create a module B1, copy dependencies, copy src, resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM