gradledependencies

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


When I try to convert a project from maven/sbt to Gradle:

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

I found a few problems, when comparing the new published pom file (by 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>

with the old one (by 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>

The pom file generated by gradle has a self-referential dependency to itself. This has caused nexus publishing to fail the sanity check. My questions are:

  1. should this be illegal? Why is gradle permitting this?

  2. why was it generated?

Gradle has a few other problems (like the deprecation of the provided scope) but so far this is the most serious of them all.


Solution

  • Fixed, turns out the problem was caused by "java-test-fixtures" plugin.

    Test fixture doesn't have a maven scope counterpart, so by default their dependencies are merged into compile scope dependencies when publishing. The problem disappeared once I disabled their publishing:

    publications {
      create<MavenPublication>("maven") {
        val javaComponent = components["java"] as AdhocComponentWithVariants
        from(javaComponent)
    
        javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) {
            skip()
        }
        javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) {
            skip()
        }
        ...
    }