如何指定 maven 的分布管理组织范围? [英] How to specify maven's distributionManagement organisation wide?

查看:40
本文介绍了如何指定 maven 的分布管理组织范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何组织许多(大约 50 多个)maven2 项目,以便它们可以部署到中央 nexus 存储库中.当使用 mvn deploy 目标时,确实需要像这样在 distributionManagement 标签中指定目标:

I'm trying to figure out how to organize many (around 50+) maven2 projects, so that they can deploy into a central nexus repository. When using the mvn deploy goal, one does need to specify the target in the distributionManagement tag like this:

<distributionManagement>
   <repository>
      <id>nexus-site</id>
        <url>http://central_nexus/server</url>
   </repository>
</distributionManagement>

现在,我不希望每个 pom.xml(50 多个)都一遍又一遍地包含这个块.我的第一个虽然是 settings.xml 文件,但似乎不可能(按设计)在那里定义它.那么,第一个问题是,为什么会这样?如果可能,我可以在 maven2 发行版的 settings.xml 中指定它,该发行版可以分发给所有开发人员.

Now, i don't want every single pom.xml (of those 50+) to contain this block over and over again. My first though would be the settings.xml file, but it seems it is not possible (by design) to define it there. So, the first question would be, why is that the case ? If it would be possible i could specify it in the settings.xml in the maven2 distribution, which could be distributed to all developers.

我发现的唯一可能的解决方案是创建一个包含这些设置的组织范围的 master-pom 项目,并通过 使所有其他 pom.xml 依赖于这个 master-pom; 标签.但这在多模块构建中看起来有点奇怪:

The only possible solution i've found was to create an organisation-wide master-pom project, that does contain these settings, and make all other pom.xml depend on this master-pom via <parent> tag. But this looks kind of strange in multi-module builds:

- master configuration POM (pm)
- Project 1 parent pom (p1 with module 1 and module 2 as modules)
    - Project 1 module pom (with pm as parent)
    - Project 2 module pom (with pm as parent)

通常我在所有文档中都读到模块 poms 应该使用父 pom,而不是一些不同的.但是在阅读了关于继承与聚合的 maven 网站后,有人写道这确实是可能的.

Usually i read in all documentation that the module poms should use the parent pom, not some different one. But after reading the maven website about Inheritance v. Aggregation it is written that it is indeed possible.

我发现的一个问题是 Maven 站点生成,它似乎在此设置中存在问题(如果没有直接反向引用,模块将无法正确链接)

One problem i found was with the maven site generation, which does seem to have problems with this setup (modules does not get linked correctly if they have no direct back-reference)

那么,这是一种有效的方法吗?还有其他更明显、更简单的解决方案吗?

So, is this a valid approach ? Any other, more obvious, simpler solution to the problem ?

推荐答案

对此的最佳解决方案是为组织中的所有项目创建一个简单的父 pom 文件项目(带有包装pom").

The best solution for this is to create a simple parent pom file project (with packaging 'pom') generically for all projects from your organization.

<?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>4.0.0</modelVersion>

    <groupId>your.company</groupId>
    <artifactId>company-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <distributionManagement>
        <repository>
            <id>nexus-site</id>
            <url>http://central_nexus/server</url>
        </repository>
    </distributionManagement>

</project>

这可以构建、发布并部署到您的本地连接,以便每个人都可以访问其工件.

This can be built, released, and deployed to your local nexus so everyone has access to its artifact.

现在对于您希望使用它的所有项目,只需包含此部分:

Now for all projects which you wish to use it, simply include this section:

<parent>
  <groupId>your.company</groupId>
  <artifactId>company-parent</artifactId>
  <version>1.0.0</version>
</parent>

此解决方案可让您轻松地将其他常见内容添加到您公司的所有项目中.例如,如果您想将 JUnit 使用标准化为特定版本,那么这将是一个完美的地方.

This solution will allow you to easily add other common things to all your company's projects. For instance if you wanted to standardize your JUnit usage to a specific version, this would be the perfect place for that.

如果你的项目使用多模块结构并且有自己的父模块,Maven 也支持链式继承,所以让你的项目的父 pom 文件引用你公司的父 pom 并且让项目的子模块不甚至是完全可以接受的了解您公司的母公司.

If you have projects that use multi-module structures that have their own parent, Maven also supports chaining inheritance so it is perfectly acceptable to make your project's parent pom file refer to your company's parent pom and have the project's child modules not even aware of your company's parent.

我从您的示例项目结构中看到,您正试图将父项目置于与聚合器 pom 相同的级别.如果您的项目需要自己的父项,我发现的最佳方法是将父项包含在与其余模块相同的级别,并将聚合器 pom.xml 文件放在所有模块目录所在的根目录下.

I see from your example project structure that you are attempting to put your parent project at the same level as your aggregator pom. If your project needs its own parent, the best approach I have found is to include the parent at the same level as the rest of the modules and have your aggregator pom.xml file at the root of where all your modules' directories exist.

- pom.xml (aggregator)
    - project-parent
    - project-module1
    - project-module2

您使用此结构所做的工作是将您的父模块包含在聚合器中,并使用根目录中的 mvn install 构建所有内容.

What you do with this structure is include your parent module in the aggregator and build everything with a mvn install from the root directory.

我们在我的组织中使用这种精确的解决方案,它经受住了时间的考验,对我们来说效果很好.

We use this exact solution at my organization and it has stood the test of time and worked quite well for us.

这篇关于如何指定 maven 的分布管理组织范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆