Project dependency is incorrect on generated pom

I have a project with 2 subprojects.
Here’s the settings.gradle:

include 'a', 'b'

‘pathfinding-gdx’ depends on ‘pathfinding.’

here’s root projects build.gradle:

project(':b'){
  ...
}

project(':a'){
  
  dependencies {
    compile project(":b")
  }
}

Each project is supposed to generate a different artifact for the maven repo.
I created a task to see each pom:

task testPom << {
  uploadArchives.repositories.mavenDeployer.pom.writeTo("$buildDir/pom.xml")
  print('created $buildDir/pom.xml')
}

Each sub project is generating its pom, they are a.pom.xml and b.pom.xml.

Pom file for project b is generating correctly. For project a, it’s just missing generating the correct dependcy on project b. Here’s what it should look like:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>common.groupId</groupId>
      <artifactId>dependency-a</artifactId>
      <version>1.0.0</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

And instead, I’m getting kind of an unresolved dependency:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>a</groupId>
      <artifactId>a</artifactId>
      <version>unspecified</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

I tried renaming the projects to make project’s b uploadArchives task happen before, but that didn’t work.

I also tried both of the following in project a’s build.gradle:

uploadArchives.dependesOn ':b:uploadArchives'
uploadArchives.dependsOn = ':b:uploadArchives'

I am not very used to gradle so I am not sure what my options are… Any help would be greatly appreciated

1 Like

Having the exact same issue right now with Gradle 3.3.

Anyone with info on how to solve that problem?

For us the issue was specifying the task too early in our project, we wrapped our task in an afterEvaluate block:

afterEvaluate {
    publishing {
        publications {
            maven(MavenPublication) {
                from components.java
            }
        }
    }
}