我是Maven的新手,正在为公司创建一个构建。我们不想连接到Maven中央仓库,并且我们的src和test代码有不同的目录结构,与超级pom中指定的不同。我认为处理这种情况的最佳方法是创建一个自定义的超级pom,但我想知道 - 我应该把超级pom放在哪里,以便我的项目pom可以引用它?它放在仓库中吗?如果是,放在哪里?
谢谢, Jeff
我的建议是创建一个父POM,让你的项目可以从中继承您的设置。这个父POM只是另一个Maven 2项目,但类型为“pom”,而不是“jar”。
例如,您可以拥有类似以下这样的父POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.projectname</groupId>
<artifactId>projectname</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>projectname</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<superprop1>this property is available in all child projects</superprop1>
<superprop2>this property is available in all child projects</superprop2>
<superprop3>this property is available in all child projects</superprop3>
</properties>
</project>
而项目的子元素可能是这样的:
<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>
<artifactId>projectname</artifactId>
<groupId>com.company.projectname</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>child-project</artifactId>
<packaging>jar</packaging>
<name>child-project</name>
<description>
My child project
</description>
</project>
在父POM中声明的所有内容现在都可以在子POM中使用。在上面的例子中,子项目将自动拥有JUnit依赖项。以这种方式进行操作还将确保环境相对于如果每个开发人员都必须处理其Maven安装的超级POM而言,是自动配置的。
false central all https://server.mycompany.com/artifactory/all snapshots all https://server.mycompany.com/artifactory/all false central all https://server.mycompany.com/artifactory/all snapshots all https://server.mycompany.com/artifactory/all artifactory artifactory这是一个Maven的配置文件,其中定义了两个仓库(repository)和两个插件仓库(pluginRepository),以及一个名为artifactory的profile。每个仓库定义了id、name、url等属性,其中snapshots节点指定是否启用快照版本。在activeProfiles节点中指定了生效的profile为artifactory。