开发者

How to manage maven sub projects not in the same directory structure?

I have a few maven projects which share some common settings - repositories, plugins and common dependencies, from the parent pom.xml.

I want to move the child projects now to separate svn location开发者_高级运维, so that they can have their own life cycle , of tags, branches and trunk. But if I move the subprojects from the directory structure, I will have to rewrite the entire common pom.xml in all the projects.

Is there a better way of handling this, so that the sub projects can still share a common parent pom.xml without residing next to each other (as folders).


I assume that you have defined a parent pom.xml like this:

<parent>
  <groupId>my.group</groupId>
  <artifactId>name</artifactId>
  <version>0.1.3-SNAPSHOT</version>
  <relativePath>../pom.xml</relativePath>
</parent>

Just remove the element <relativePath/>, then the parent is accessed like all other dependencies, either from your local repository or your own nexus repository. Thus the relative path is not necessary, this does not depend on directory structures.


I don't know why you have to explicitly reference the parent pom file.

What I do usually is have the parent pom as a project like so:

<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>4.0.0</modelVersion>
    <groupId>com.blah.commons</groupId>
    <artifactId>project-standards</artifactId>
    <name>Common Standards</name>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
...

Note the <packaging>pom</packaging> element

and in each project/module, would depend on the standards pom.

<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">

    <parent>
        <groupId>com.blah.commons</groupId>
        <artifactId>project-standards</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.blah.project</groupId>
    <artifactId>xyz-core</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>project xyz core module</name>
...

Note the <parent> element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜