为什么 Gradle 发布的每个 pom 文件都有自引用依赖?

Why does every pom file published by Gradle has a self-referential dependency?

当我尝试将项目从 maven/sbt 转换为 Gradle 时:

https://github.com/tek/splain/blob/nexusRelease/Dev1/build.gradle.kts

我在比较新发布的 pom 文件时发现了一些问题(gradle):

...
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.tryp</groupId>
  <artifactId>splain_2.13.6</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>2.13.6</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.13.6</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.tryp</groupId>
      <artifactId>splain_2.13.6</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>
  </dependencies>
</project>

与旧的(由 sbt):

...
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>2.13.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.13.5</version>
        </dependency>
        <dependency>
            <groupId>com.chuusai</groupId>
            <artifactId>shapeless_2.13</artifactId>
            <version>2.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>dev.zio</groupId>
            <artifactId>zio_2.13</artifactId>
            <version>1.0.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.specs2</groupId>
            <artifactId>specs2-core_2.13</artifactId>
            <version>4.5.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

gradle生成的pom文件对自身有自引用依赖。这导致 Nexus 发布无法通过健全性检查。我的问题是:

  1. 这应该是违法的吧?为什么 gradle 允许这样做?

  2. 为什么会生成?

Gradle 还有一些其他问题(比如 provided 范围的弃用),但到目前为止这是所有问题中最严重的。

已修复,原来问题是由“java-test-fixtures”插件引起的。

测试夹具没有对应的 maven 作用域,因此默认情况下,它们的依赖项在发布时会合并到编译作用域依赖项中。一旦我禁用他们的发布,问题就消失了:


                val javaComponent = components["java"] as AdhocComponentWithVariants
                from(javaComponent)

                javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
                javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }