Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

java - Publsihing Kotlin Library so that Gradle resolves transitive dependencies

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 that benefit from the same extended API.

I'm trying to clean this up for the sake of maintainability, and publish a Kotlin library of these extension functions to our company's Artifactory instance.

So far everything is going as planned. The library is successfully built on Jenkins, and published to Artifactory using the Artifactory Jenkins plugin.

The issue I'm running in to is that consumers of the dependency also have to include implementation org.json:json:<version> in their build file.

Gradle is smart enough to resolve transitive dependencies, so I suspect I'm not declaring them correctly.

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 looks like:

{
  "formatVersion": "1.1",
  "component": {
    "group": "com.example.extensions",
    "module": "ext-org-json",
    "version": "0.0.1"
  },
  "createdBy": {
    "author": "[email protected]",
    "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, this does not seem to help. Consumers still don't get the benefit of Gradle fetching the org.json dependency for them.

Could someone point me in the right direction to do this properly? Gradle Metadata, POM file, or otherwise, any help is appreciated!

question from:https://stackoverflow.com/questions/65836572/publsihing-kotlin-library-so-that-gradle-resolves-transitive-dependencies

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...