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

csbfibhn  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(216)

当我尝试将项目从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>

字符串
古人云:

...
    <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允许这样做?
1.为什么会产生呢?
Gradle还有其他一些问题(比如provided作用域的弃用),但到目前为止,这是其中最严重的一个。

6bc51xsx

6bc51xsx1#

修复,原来问题是由“java-test-fixtures”插件引起的。
测试fixture没有对应的maven作用域,所以默认情况下,它们的依赖在发布时会合并到编译作用域依赖中。一旦我禁用了它们的发布,问题就消失了:

publications {
  create<MavenPublication>("maven") {
    val javaComponent = components["java"] as AdhocComponentWithVariants
    from(javaComponent)

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

字符串

相关问题