maven - 如何编译所有模块但只安装/部署选定的模块?

标签 maven jenkins maven-3 pom.xml maven-deploy-plugin

我有一个典型的多模块 Maven 项目。

  • 有一个 Jenkins 作业,它构建所有快照并将其部署到内部存储库。
  • 还有另一个 Jenkins 构建,它检查代码、更新所有 pom 版本以及构建和部署版本化的 Artifact 。

  • 我想通过仅部署所需的 Artifact 来优化后者:即 2 3 来自 100+ 模块。

    该构建仍应编译和测试所有模块,但仅将选定的模块 Artifact 安装/部署到内部存储库。

    问题 : 有办法吗?

    最佳答案

    在这种情况下,您可以在您的聚合器/父项目(主构建应该从该项目开始)中定义以通过属性跳过安装和部署执行,以便默认通过所有模块禁用它们。然后,在仍应执行此操作的少数模块中,您可以覆盖特定属性以再次启用它们。

    由于整个操作针对的是 CI 作业,我还建议将此行为包装在 maven profile 中。如下:

    在您的聚合器/父项目中,您可以定义:

    <profiles>
        <profile>
            <id>ci-job</id>
            <properties>
                <disable.install.deploy>true</disable.install.deploy>
                <maven.install.skip>${disable.install.deploy}</maven.install.skip>
                <maven.deploy.skip>${disable.install.deploy}</maven.deploy.skip>
            </properties>
        </profile>
    </profiles>
    

    上面的代码片段在 ci-job 内定义描述一个新的属性,disable.install.deploy , 设置为 true默认情况下。然后将其值传递给 maven.install.skip maven-install-plugin 的属性:

    Set this to true to bypass artifact installation. Use this for artifacts that does not need to be installed in the local repository.



    maven.deploy.skip maven-deploy-plugin 的属性(property):

    Set this to 'true' to bypass artifact deploy



    因此,运行以下命令:

    mvn clean install -Pci-job

    将有效地跳过整个构建(跨所有模块)的安装和部署目标执行。

    然而,这是工作的一半。在您仍然需要此操作的几个模块中,您可以定义以下内容:
    <profiles>
        <profile>
            <id>ci-job</id>
            <properties>
                <disable.install.deploy>false</disable.install.deploy>
            </properties>
        </profile>
    </profiles>
    

    那是。保持相同的配置文件名称也将通过相同的全局构建调用激活,但是将 key 属性设置为 false并因此为将添加此配置文件的模块再次启用安装和部署。

    关于maven - 如何编译所有模块但只安装/部署选定的模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37056037/

    相关文章:

    maven - 无法在 Android Studio 上使用 Gradle 安装 Kontakt Android SDK

    java - 使用 Maven 构建 OSGi 应用程序

    java - 在cmd行中使用mvn安装的Eclipse项目

    windows - Jenkins 无法连接到 Windows Docker Toolbox 守护进程

    同一组中的Maven并行下载依赖项

    java - 如何让 Eclipse 将文件导出到与源不同的位置?

    deployment - Jenkins-将构建推广到不同的环境

    java - Jenkins 和 Maven : how to package some files in my JAR and unpack them before running a test?

    java - Maven jar-with-dependencies 不会覆盖文件

    sonarqube - Sonar Maven 插件 : How do I exclude test source directories?