简体   繁体   English

将两个Java Maven项目合并为一个

[英]Merge two Java Maven projects into one

I am working on a Java/Maven project. 我正在开发Java / Maven项目。 I am using another project as a JAR library, everything is working fine. 我正在使用另一个项目作为JAR库,一切正常。

My manager wants me to use only one Git repository. 我的经理要我只使用一个Git存储库。 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 ) 困惑于如何做到这一点以及我需要记住的事情(比如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] 创建新项目并尝试复制src部分并粘贴到新项目src [似乎不正确]
  • 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. 我的经理要我只使用一个Git存储库。 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. 基本上将两个基于Maven的项目放在一个Git存储库中并生成一个将同时使用原始项目和外部库的Maven项目是两个不同的任务。 Since under Git repository you have a file system that can look like: 因为在Git存储库下你有一个文件系统,它看起来像:

|__.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: 另一方面,如果目标是一起构建两个项目而不是考虑使用多模块 Maven项目:

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: 我在第二个例子中提到的带有包装pom的POM将包含一个模块列表:

<?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. 让我们假设你有两个maven项目A和B.现在在你的intllij-idea中创建一个新的项目C. In project C, create a new module A1. 在项目C中,创建一个新模块A1。 Copy the dependencies and build, properties (if present) from pom.xml of A to the pom.xml of A1. 将依赖关系和构建,属性(如果存在)从A的pom.xml复制到A1的pom.xml。 Now copy your src directory from project A to src of A1 and so the resources. 现在将您的src目录从项目A复制到A1的src以及资源。 Repeat the same process for your project B, ie create a module B1, copy dependencies, copy src, resource. 对项目B重复相同的过程,即创建模块B1,复制依赖项,复制src,资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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