Joe*_*Joe 2 java maven-2 release-management maven
环境:Maven 2.2.1 我在svn(projectA,projectB)下有两个java项目.我的maven结构如下..
For projectA
pom.xml (contains ProjectA parent pom definitions)
module moduleA
module moduleB
For projectB
pom.xml (contains ProjectB parent pom definitions)
module moduleC
module moduleD
Run Code Online (Sandbox Code Playgroud)
projectA/pom.xml和projectB/pom.xml包含常见的定义,如junit,selenium,compiler,eclipse插件,这两个项目都是通用的.(例如下面给出)
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency
Run Code Online (Sandbox Code Playgroud)
我应该如何创建/组织包含此类公共定义的组织特定项目pom,以便单个项目不必重新创建/维护.有人可以提供一些已经完成此操作的片段或项目吗?
EDIT1:
公司/ pom.xml的
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>company</artifactId>
<packaging>pom</packaging>
<name>parent</name>
<version>1.0.0</version>
<build>
<defaultGoal>install</defaultGoal>
</build>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
了projectA/pom.xml的
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>company</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<name>projectA</name>
<version>1.0.0</version>
<modules>
<module>moduleA</module>
Run Code Online (Sandbox Code Playgroud)
<build>
<defaultGoal>install</defaultGoal>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Run Code Online (Sandbox Code Playgroud)
了projectA/moduleA/pom.xml的
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>projectA</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>moduleA</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>moduleA</name>
<build>
<finalName>moduleA</finalName>
<defaultGoal>install</defaultGoal>
</build>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
引发以下错误:
Project ID: com.mycompany:moduleA
POM Location: c:\temp\maven\projectA\moduleA\pom.xml
Validation Messages:
[0] 'dependencies.dependency.version' is missing for commons-lang:comm
ons-lang:jar
[1] 'dependencies.dependency.version' is missing for javax.servlet:ser
vlet-api:jar
Run Code Online (Sandbox Code Playgroud)
我会认真考虑将依赖项添加到"超级"POM中,这会不必要地将项目耦合在一起(但可能暗示如果项目不是完全不同,那么它们应该合并在一起).我认为@lexicore的最后一条评论也很尖锐,为了扩展OOP类比,它也感觉像是"混合抽象层次".
Alex Gitelman提供了正确的答案,您需要使用dependencyManagement,如此处所示的依赖范围
Maven3 应该支持POM片段,请参阅如何使用Maven 3 mixins?我一直在等待.
我们有一个组织ÜberPOM,但这只包含:
<organization>
<name>...</name>
<url>...</url>
</organization>
<developers>
<developer>
<id>...<id>
<name>...</name>
<email>...</email>
<roles>
<role>...</role>
</roles>
</developer>
<distributionManagement>
...
</distributionManagement>
<repositories>
<!-- your proxy repo here -->
</repositories>
Run Code Online (Sandbox Code Playgroud)
这些变化非常少(如果我们更改我们的存储库/分发管理,那么所有项目都必须更改,如果开发人员离开或加入,我们可以随时更新项目POM).
依赖性特别属于所考虑的模块,仅仅因为两个独立项目碰巧共享依赖性现在并不意味着它们总是会.我完全理解为每个项目(编译器插件,报告插件,junit等)复制'n'粘贴XML的烦恼,但每个项目中不同的活动级别肯定意味着它们在某些方面有所不同.
WRT级联构建在持续集成中,如果项目A要求更改超级依赖关系POM,那么所有其他项目将被迫重建 - 如果你只有2个项目,可能没问题,但即便如此,你还是在提交之前检查并构建两个项目改变?
| 归档时间: |
|
| 查看次数: |
6470 次 |
| 最近记录: |