如何仅将 pom 文件部署到 Maven 中的快照存储库?

发布于 2024-11-09 20:13:48 字数 971 浏览 5 评论 0原文

当运行 mvn deploy 并且版本是 SNAPSHOT 版本时,我希望能够仅部署 POM 工件(文件),而无需主要工件(JAR、WAR 等)。

为什么?

我们有几个开发人员致力于多个 Maven 项目。我们有一个 Hudson 服务器,每个 Maven 项目和版本都有一个作业(例如 foo-1.2、foo-1.3)。每个作业都会构建项目并将其部署到 Nexus 服务器(成功后)。正在开发的 Maven 项目通过在版本中使用 -SNAPSHOT 后缀进行标记。例如:1.2-快照、1.3-快照。

以下是开发人员的工作如何因这种架构而受损的示例场景。

假设有两个 Maven 项目:foo-core 和 foo-webapp,版本均为 1.2-SNAPSHOT。

  • 开发人员 A 正在开发 foo-core,进行了一些更改并编译了它。
  • 开发人员 A 继续工作,但在 foo-webapp 上。
  • 开发人员 B 开始工作并更改 foo-core。它提交了他的工作并将其推送给 SCM。
  • Hudson由SCM触发;构建 foo-core 并将其部署到 Nexus 中的快照存储库。
  • 开发人员 A 正在 foo-webapp 上运行 mvn install。 Maven 正在检查 Nexus,发现 Nexus 中有更新版本的 foo-core。它下载它(填充了开发人员 B 的更改),然后编译失败,因为开发人员 A 所做的更改不在本地存储库中的 jar 中。下载会覆盖开发人员 A 安装的文件。

现有解决方案

我研究了 maven-deploy-plugin,但此插件部署了附加到项目的所有工件。如果他们有办法配置要部署的工件,那就太好了。

问题:有没有办法解决这个问题,而不需要基于maven-deploy-plugin编写我自己的部署插件?

I would like to be able to deploy only the POM artifact (file) without the main artifact (JAR, WAR, etc), when running mvn deploy and version is a SNAPSHOT version.

Why?

We several developers working on multiple Maven projects. We have a Hudson server with a job per Maven project and version (e.g. foo-1.2, foo-1.3). Each job builds the project and deploys it to a Nexus server (upon success). Maven projects under development are marked as such by using -SNAPSHOT postfix in the version. For example: 1.2-SNAPSHOT, 1.3-SNAPSHOT.

Here's a sample scenario how a developer work is damaged due to this architecture.

Assume two Maven projects: foo-core and foo-webapp, both at version 1.2-SNAPSHOT.

  • Developer A is working on foo-core, made several changes and compiled it.
  • Developer A continues to work, but on foo-webapp.
  • Developer B started working and changing foo-core. It commits his work and pushes it to the SCM.
  • Hudson is triggered by SCM; Builds foo-core and deploys it to the snapshot repository in Nexus.
  • Developer A is running mvn install on foo-webapp. Maven is checking with Nexus, and finds that there is a newer version of foo-core in Nexus. It downloads it (filled with developer B changes) and than it fails compilation, since the changes made by developer A are not in the jar located in the local repository. The download overrides the file installed there by developer A.

Existing Solutions

I looked into maven-deploy-plugin, but this plugin deploys all artifacts attached to the project. If they had a way to configure which artifacts to deploy, it would have been great.

Question: Is there any way to solve this without resorting to writing my own deploy plugin, based on maven-deploy-plugin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡写薰衣草的香 2024-11-16 20:13:48

基本上是传递给 -Dfile 参数,而不是工件,而是传递 pom.xml。运行命令,耶! mvn deploy 现在不会给您带来任何问题。这是一个示例部署命令:

$ mvn deploy:deploy-file -DpomFile=pom.xml -Dfile=./pom.xml -DgroupId=my.group.id -DartifactId=artifact-id -DrepositoryId=bigdata-upload-snapshots -Durl=http://maven.mymaven.com/content/repositories/snapshots/

此操作的先决条件是在 settings.xml 中添加存储库

[编辑]:我已提供参数 -DgroupId-DartifactId示例部署命令中的项目,但它们不是必需的(请参阅下面 Zac 的评论)

Basically to the -Dfile parameter, instead of the artifact, pass the pom.xml. Run the command and yay! mvn deploy won't give you any issues now. Here's a sample deploy command :

$ mvn deploy:deploy-file -DpomFile=pom.xml -Dfile=./pom.xml -DgroupId=my.group.id -DartifactId=artifact-id -DrepositoryId=bigdata-upload-snapshots -Durl=http://maven.mymaven.com/content/repositories/snapshots/

A prerequisite for this is that the repository be added in your settings.xml

[Edit]: I have supplied the parameters -DgroupId and -DartifactId of the project in the sample deploy command but they're not required (refer to Zac's comment below)

剪不断理还乱 2024-11-16 20:13:48

我从未听说过这种可能性,如果有可能的话,我也会感到非常惊讶。由于 pom 和生成的工件是某种单元,因此(对我来说)只部署其中的一部分是没有意义的。

尽管如此,您应该考虑创建一个单独的 pom 项目,其中指定了您可能想要在 JAR/WAR 项目上使用的依赖项和插件,如下所示:

<groupId>foo.bar</groupId>
<artifactId>my-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

然后由您的 JAR/WAR 项目继承该 pom 项目,如下所示:

<parent>
    <groupId>foo.bar</groupId>
    <artifactId>my-pom</artifactId>
    <version>1.0.0</version>
</parent>

这称为 项目继承。您可以独立于“子”工件来更改和部署您的 pom 项目。

阅读动机后编辑

据我了解,您希望阻止 Maven 解析存储库中的 SNAPSHOT 工件(以便本地版本不会被覆盖)。您是否尝试过使用 mvn -nsu 选项(请参阅mvn -help)?

-nsu,--no-snapshot-updates             Suppress SNAPSHOT updates

我从未尝试过,但发现了这个报告的问题。尽管如此,我还是会尝试一下(因为该问题尚未发表评论)。

I never heard of such a possibility and also would be very astonished if that would be possible. As the pom and the resulting artifact are some kind of unit it would make no scence (to me) to deploy only parts of them.

Nevertheless you should consider to make a separate pom project which specified dependencies and plugins you might want to use on your JAR/WAR projects like this:

<groupId>foo.bar</groupId>
<artifactId>my-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

and then inherit that pom project by your JAR/WAR projects like this:

<parent>
    <groupId>foo.bar</groupId>
    <artifactId>my-pom</artifactId>
    <version>1.0.0</version>
</parent>

This is called project inheritance. You can change and deploy your pom project independent of the "child" artifacts.

EDIT after reading motivation:

As I understand you want to prevent maven to resolve SNAPSHOT artifacts from a repository (so that local version won't be overwritten). Have you ever tried to use the mvn -nsu option (see mvn -help)?

-nsu,--no-snapshot-updates             Suppress SNAPSHOT updates

I never tried it but found this reported issue. Nevertheless I would give it a try (as the issue is not commented yet).

逆光飞翔i 2024-11-16 20:13:48

这对我来说仅适用于部署pom 文件(例如,在现有 jar 旁边):
注意:您需要还指定打包,否则它将作为 .xml 文件上传,这不是您想要的。)

mvn deploy:deploy-file \
-Dfile=pom.xml \
-Dpackaging=pom \
-DgroupId=com.mycompany.package \
-DartifactId=my-artifact \
-Dversion=2.0.1 \
-DrepositoryId=serverIdFromSettingsXMLForCredentials \
-Durl=http://repositoryserver/myrepo/

This works for me for deploying a pom file only (e.g next to an existing jar):
(Note: you need to specify packaging also, otherwise it will be uploaded as an .xml file which is not what you want.)

mvn deploy:deploy-file \
-Dfile=pom.xml \
-Dpackaging=pom \
-DgroupId=com.mycompany.package \
-DartifactId=my-artifact \
-Dversion=2.0.1 \
-DrepositoryId=serverIdFromSettingsXMLForCredentials \
-Durl=http://repositoryserver/myrepo/
嗫嚅 2024-11-16 20:13:48

这并不完全是这些人所要求的答案。我的情况是我只想部署父 pom。我在子模块中使用 spring-boot-thin-layout 。这需要将父模块部署到工件中。我将以下内容添加到我的项目中。它允许跳过安装和/或部署阶段。

在我的父 pom 中:

<properties>
    <disable.install>true</disable.install>
    <disable.deploy>true</disable.deploy>
    <enable.deployAtEnd>true</enable.deployAtEnd>
</properties>

<profiles>
    <profile>
        <id>deploy-parent</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <disable.install>true</disable.install>
            <disable.deploy>true</disable.deploy>
            <deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
        </properties>
        <build>
            <finalName>${project.version}</finalName>
        </build>
    </profile>
</profiles>

在我的子 pom 或任何您不想与父 pom 一起部署的模块中:

<properties>
    <maven.install.skip>${disable.install}</maven.install.skip>
    <maven.deploy.skip>${disable.deploy}</maven.deploy.skip>
    <deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>

因此,当我在父 pom 上运行 mvn deploy 时,它将编译所有模块,不要在任何东西上运行安装,然后最后部署任何没有`

Not exactly the answer these folks were asking for. My situation was I wanted to deploy only the parent pom. I'm using the spring-boot-thin-layout in a child module. This requires the parent module be deployed into artifactory. I added the following into my project. It enables skipping of install and/or deploy phase.

In my parent pom:

<properties>
    <disable.install>true</disable.install>
    <disable.deploy>true</disable.deploy>
    <enable.deployAtEnd>true</enable.deployAtEnd>
</properties>

<profiles>
    <profile>
        <id>deploy-parent</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <disable.install>true</disable.install>
            <disable.deploy>true</disable.deploy>
            <deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
        </properties>
        <build>
            <finalName>${project.version}</finalName>
        </build>
    </profile>
</profiles>

And the in my child pom(s) or any module you don't want deployed with parent:

<properties>
    <maven.install.skip>${disable.install}</maven.install.skip>
    <maven.deploy.skip>${disable.deploy}</maven.deploy.skip>
    <deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>

So effectively when I run mvn deploy on the parent pom, it will compile all the modules, not run install on anything, and then at the end deploy any module not having `

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文