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!