【问题标题】:Generate parent pom for existing project modules为现有项目模块生成父 pom
【发布时间】:2020-10-07 22:41:54
【问题描述】:

我有以下项目模块。每个模块都有自己的 pom.xml 。现在我想生成一个父 POM(对于像下面这样的现有模块)。有没有办法做到这一点?我知道如果我们正在创建全新的项目,我们可以采取一种方法,但我在这里需要的是我已经有了一个项目结构。

  1. project-module-1
  2. project-module-2
  3. project-module-3
  4. project-module-4

感谢您的帮助

【问题讨论】:

    标签: maven parent-pom


    【解决方案1】:

    你需要稍微修改一下你现有的项目,这并不难。

    你的项目结构是这样的

    父母pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example</groupId>
        <artifactId>sample-parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <description>sample</description>
        <url>http://example.com</url>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
        <modules>
            <module>project-module-1</module>
            <module>project-module-2</module>
            <module>project-module-3</module>
            <module>project-module-4</module>        
        </modules>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
            </plugins>
        </build>
    </project>
    

    孩子pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.example</groupId>
            <artifactId>sample-parent</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </parent>
        <groupId>com.example</groupId>
        <artifactId>project-module-1</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <description>sample</description>
        <url>http://example.com</url>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
            </plugins>
        </build>
    </project>
    

    示例项目源代码:https://github.com/donhuvy/maven_parent_childs/archive/master.zip

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 2010-12-31
      • 2021-02-27
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多