【问题标题】:Why does maven release plugin allow for SNAPSHOT version in dependency management?为什么 maven 发布插件允许在依赖管理中使用 SNAPSHOT 版本?
【发布时间】:2011-01-06 13:12:42
【问题描述】:

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

令人担忧的是,SNAPSHOT 版本可以在dependencyManagement 中定义。虽然在执行 maven 发布时,pom 允许在依赖管理中使用 SNAPSHOT 版本发布。为什么?

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

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

【问题讨论】:

    标签: maven-2 snapshot dependency-management maven-release-plugin


    【解决方案1】:

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

    一家名为 smartics(小写 s)的公司创建了一条规则 (NoSnapshotDependenciesInDependencyManagementRule) 以防止出现此问题。

    您基本上需要将以下内容添加到您的父 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>
    

    【讨论】:

      【解决方案2】:

      令人担忧的是,SNAPSHOT 版本可以在dependencyManagement 中定义。虽然在执行 maven 发布时,pom 允许在依赖管理中使用 SNAPSHOT 版本发布。为什么?

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

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

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

      【讨论】:

      • 谢谢。我们使用的是 2.0-beta-9。我们将看看这些 jira 票
      • 关于此问题的新 JIRA MRELEASE-454。看起来它在 2.2.2 中已修复,但至少在 2.4 中被重新引入。
      猜你喜欢
      • 2011-06-18
      • 2016-07-24
      • 2015-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 2021-07-11
      • 2015-10-17
      相关资源
      最近更新 更多