6

我是 Maven 新手,最近安装了 nexus。现在我想创建一个父 POM,以便我公司内的所有项目都可以使用它。这是我的父母 POM。

<?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/maven-v4_0_0.xsd">
    <modelVersion>1.0.0</modelVersion>
    <groupId>com.mycomp</groupId>
    <artifactId>parent-pom-android</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>Android Parent POM</name>

    <repositories>
        <repository>
            <id>nexus-repo</id>
            <url>http://10.10.10.230:8081/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus-repo</id>
            <name>confiz-repo</name>
            <url>http://10.10.10.230:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
 </project>

现在我在哪里放置这个 POM 文件,以便我的其他 POM 文件可以继承它?

4

4 回答 4

10

如果你把这个父 pom 放在一个名为 android 的文件夹中,那么将在同一个文件夹中使用它的项目,就像这样。

  • 安卓
  • pom.xml
  • 安卓项目-1
    • pom.xml

然后项目 pom.xml 可以通过将其放在其 pom.xml 的顶部来使用父 pom:

<parent>
    <groupId>parent.group</groupId>
    <artifactId>parent.artifact</artifactId>
    <version>${version.number}</version>
    <relativePath>../</relativePath>
</parent>

然后,您可以在将来扩展此架构,如下所示:

  • 移动的
    • pom.xml
    • 安卓
      • pom.xml
      • 安卓项目-1
      • android-project-2
    • 苹果手机
      • pom.xml
      • iphone-project-1

这使您可以定义 android 项目的通用配置、iphone 项目的通用配置和所有移动项目的通用配置。等等

于 2013-01-18T14:14:04.617 回答
4

You have to deploy your project to an internal Maven repository. To do that, you first need to configure a Maven repository server (I recommend using Apache Archiva), and then point your pom.xml and settings.xml to the server: http://archiva.apache.org/docs/1.4-M3/userguide/deploy.html

After deploying it, you can point all the projects from your company to use that pom as parent pom. You can use the same strategy to create internal project dependencies. That goes very well in a continuous integration environment.

于 2013-01-18T14:16:05.453 回答
1

对于每个子 pom,放置对父 pom 的引用。

<parent>
    <groupId>com.mycomp</groupId>
    <artifactId>parent-pom-android</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>relative/path/to/parent/pom</relativePath>
</parent>

relativePath is computed starting from the child pom

于 2013-01-18T14:15:29.230 回答
1

Packaging type should be pom instead of apk.

于 2013-07-07T20:22:01.853 回答