Library Dependencies not being resolved

My team uses a set of extension functions for JSON-Java that originated in one project, and has now been copy/pasted in to various new projects.

For the sake of maintainability I’m trying to clean this up by consolidating all these extensions in a Kotlin library that can be consumed as a dependency by the different projects.

We use Jenkins to build the library JAR, and the Artifactory Jenkins plugin to publish it to our company’s Artifactory instance. These steps are working as expected.

The bummer is that consumers of the dependency still have declare implementation org.json:json:<version> in their build file themselves. I know Gradle is smart enough to resolve transitive dependencies, so I have to assume I’m doing something wrong in the build/publish process.

I decided to start by trying Gradle Module Metadata rather than a POM file since I’m not doing anything Maven-centric.

Here’s what that file looked like:

{
  "formatVersion": "1.1",
  "component": {
    "group": "com.example.extensions",
    "module": "ext-org-json",
    "version": "0.0.1"
  },
  "createdBy": {
    "author": "email@email.email",
    "gradle": {
      "version": "6.7"
    }
  },
  "variants": [
    {
      "name": "api",
      "attributes": {
        "org.gradle.usage": "java-api",
        "org.gradle.category": "library",
        "org.gradle.libraryelements": "jar"
      },
      "dependencies": [
        {
          "group": "org.json",
          "module": "json",
          "version": "20201115",
          "reason": "This module exists to extend its API."
        },
        {
          "group": "org.jetbrains.kotlin",
          "module": "kotlin-stdlib",
          "version": "1.4.21"
        }
      ]
    }
  ]
}

Unfortunately, the module metadata didn’t seem to do it, so I then tried this POM file, which didn’t seem to work either:

<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>com.example.extensions</groupId>
    <artifactId>ext-org-json</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>JSON in Java Extensions</name>
    <description>
        Useful extension API for JSON in Java.
    </description>
    
    <licenses>
        <license>
            <name>License Name</name>
            <comments>
               Legalese words that mean things.
            </comments>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Ryan Smith</name>
            <email>email@email.email</email>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20201115</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.4.21</version>
        </dependency>
    </dependencies>

</project>

This is my first time doing something like this, so any direction is deeply appreciated!

I am not sure how you are publishing your library but as of Gradle 6 it should be creating the .pom and .module files for you:
https://docs.gradle.org/current/userguide/publishing_setup.html

I noticed in your .module file you have incorrectly defined your version which requires it be an object like this:

"version": { "requires": "20201115" }

However from a quick look it seems your .pom file should have worked.

Make sure in the project you are testing the consumption of your library that it doesn’t have transitive set to false any where:

You may want to just create a new project from scratch to rule out anything else.

Lastly you might want to try out --scan, it provides a detailed report of dependency tree which might help you hunt down your issue:
https://scans.gradle.com/

You can also try dependencyInsight passing it your ext-org-json library.
https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html#sec:identifying_reason_dependency_selection
You may also want to try it with the json library to see what else could be trying to pull it in.