为什么maven发布插件允许在依赖管理中使用SNAPSHOT版本?

发布于 2024-08-18 10:49:43 字数 381 浏览 14 评论 0原文

我们有 1 个公司父 pom。这使用 dependencyManagement 来管理所使用的所有工件的所有依赖项的版本。

令人担忧的是,SNAPSHOT 版本可以在 dependencyManagement 中定义。但maven发布时,dependencyManagement中允许以SNAPSHOT版本发布pom。为什么?

如果我将一个子项目指向公司父 pom 的已发布版本,并且该子项目使用 dependencyManagement 中定义的依赖项(尽管它是 SNAPSHOT 版本),则我无法发布该子项目。

为什么 Maven 允许发布 dependencyManagement 中定义的工件的 SNAPSHOT 版本?如果定义了 SNAPSHOT 版本,如何配置 Maven 发布插件失败?

We have 1 company parent pom. This uses dependencyManagement to manage the versions for all the dependencies of all the artifacts used.

What is alarming, is that SNAPSHOT versions can be defined in dependencyManagement. Though when maven release is performed, the pom is allowed to be released with SNAPSHOT version in dependencyManagement. Why?

If I point a child project to a released version of the company parent pom, and this child project uses a dependency defined in dependencyManagement though it's a SNAPSHOT version, I'm unable to release the child project.

Why does Maven allow SNAPSHOT version for an artifact defined in dependencyManagement to be released? And how can I configure the maven release plugin to fail if there is a SNAPSHOT version defined?

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

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

发布评论

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

评论(2

萌酱 2024-08-25 10:49:43

令人担忧的是,SNAPSHOT 版本可以在 dependencyManagement 中定义。但maven发布时,dependencyManagement中允许以SNAPSHOT版本发布pom。为什么?

我希望 maven-release-plugin 更新 <发布时的代码>dependencyManagement。实际上,有一些关于此的 Jira,例如 MRELEASE-91MRELEASE-202 可能会影响您。

所以问题是:您使用的是哪个版本的插件?

但说实话,目前还不清楚哪些版本受到 MRELEASE-202 的影响,评论令人困惑(所以我想知道问题是否已解决)。无论如何,如果您使用的版本受到影响,请升级到更新的版本。如果错误/回归(我认为这是一个错误)仍然存在,那么提出一个新问题。

What is alarming, is that SNAPSHOT versions can be defined in dependencyManagement. Though when maven release is performed, the pom is allowed to be released with SNAPSHOT version in dependencyManagement. Why?

I would expect the maven-release-plugin to update SNAPSHOT versions in dependencyManagement upon release. Actually, there are some Jira about this, for example MRELEASE-91 and MRELEASE-202 that may affect you.

So the question is: which version of the plugin are you using?

But to be honest, it's not really clear what versions are affected by MRELEASE-202, the comments are confusing (so I wonder if the issue is fixed or not). Anyway, if the version you are using is affected, then upgrade to a more recent version. And if the bug/regression (I think it's a bug) is still there, then raise a new issue.

双手揣兜 2024-08-25 10:49:43

我不知道“为什么”的答案(我个人认为这是一个错误),但我有办法防止这种情况发生:使用 Maven Enforcer 插件。

一家名为 smarttics(小写 s)的公司创建了一条规则 (NoSnapshotDependencyInDependencyManagementRule)来防止出现这个问题。

您基本上需要将以下内容添加到您的父 POM 中:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.4.1</version>
  <executions>
    <execution>
      <id>enforce-project-rules</id>
      <phase>test</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <NoSnapshotDependenciesInDependencyManagementRule
            implementation="de.smartics.maven.enforcer.rule.NoSnapshotsInDependencyManagementRule">
            <onlyWhenRelease>true</onlyWhenRelease>
            <checkOnlyResolvedDependencies>false</checkOnlyResolvedDependencies>
          </NoSnapshotDependenciesInDependencyManagementRule>
        </rules>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>de.smartics.rules</groupId>
      <artifactId>smartics-enforcer-rules</artifactId>
      <version>1.0.2</version>
    </dependency>
  </dependencies>
</plugin>

I do not have the answer as to 'why' (personally I think it's a bug), but I have a way to prevent this happening: use the Maven Enforcer plugin.

A company called smartics (lowercase s) have created a rule (NoSnapshotDependenciesInDependencyManagementRule) to prevent this exact problem.

You basically need to add the following to your parent POM:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.4.1</version>
  <executions>
    <execution>
      <id>enforce-project-rules</id>
      <phase>test</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <NoSnapshotDependenciesInDependencyManagementRule
            implementation="de.smartics.maven.enforcer.rule.NoSnapshotsInDependencyManagementRule">
            <onlyWhenRelease>true</onlyWhenRelease>
            <checkOnlyResolvedDependencies>false</checkOnlyResolvedDependencies>
          </NoSnapshotDependenciesInDependencyManagementRule>
        </rules>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>de.smartics.rules</groupId>
      <artifactId>smartics-enforcer-rules</artifactId>
      <version>1.0.2</version>
    </dependency>
  </dependencies>
</plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文