Pom.xml published by maven-publish plugin does not contain dependencies

This is similar to the old topics, but none resolved. Didn’t find a way to add posts there, so here is another one. This is a big issue, most likely a bug. pom.xml that gets published is minimal:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>pom</packaging>
</project>

That is it.

Please, help is needed. I tried adding afterEvaluate as mentioned on one of the threads but depending on which part I wrap in it I either get nothing published at all or an error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':mdm.contract.api'.
> Cannot configure the 'publishing' extension after it has been accessed.

What can be done to work around this problem?

Here’s the actual code used:

javaProject.publishing {
  repositories {
    maven {
      url '...'
    }
  }
  
  publications {
    code(org.gradle.api.publish.maven.MavenPublication) {
      groupId     '...'
      artifactId  javaProject.getName()
      version     javaProject.version
      from        javaProject.components.java
    }
    
    sources(org.gradle.api.publish.maven.MavenPublication) {
      groupId     '...'
      artifactId  javaProject.getName()
      version     javaProject.version
      artifact    javaProject.sourcesJar {
        classifier "sources"
      }
    }
  }
  
  println javaProject.configurations.runtime.allDependencies
}

These projects get java, maven and maven-publish plugins applied at least.