yannicklamprecht / WorldBorderAPI

A world border api that allows it to define a world border per player
MIT License
125 stars 13 forks source link

Broken dependency loading in gradle #102

Closed Szczurowsky closed 1 year ago

Szczurowsky commented 1 year ago

Describe the bug Builded libraries (from 1.18.2 version) contain few variants. When gradle uses worldborderapi as compile only dependency it doesn't load a dependency overall.

1.18.1 (Working)

  "variants": [
    {
      "name": "apiElements",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.jvm.version": 17,
        "org.gradle.libraryelements": "jar",
        "org.gradle.usage": "java-api"
      },
      "files": [
        {
          "name": "worldborderapi-1.181.1-dev.jar",
          "url": "worldborderapi-1.181.1-dev.jar",
          "size": 23716,
          "sha512": "c0bc0836507b61f6f8c7f95418843d5be5c941fb52a21bd35b50eda5277bf092fc2b4d236fc514773b9a3541f0411892e87f29f9ac7eb80a011edbe4162418cd",
          "sha256": "2b35c148d1400f4bae3e672703dcae1ed622fff055d2109628a85245a121e533",
          "sha1": "17e10e7e6349b8dc8d195aed8e480a2c14d7884d",
          "md5": "9ac48dfc0b0ce61daa74dcfd1649d7b3"
        }
      ]
    },

1.18.2 (Not working)

  "variants": [
    {
      "name": "apiElements",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.jvm.version": 17,
        "org.gradle.libraryelements": "jar",
        "org.gradle.usage": "java-api"
      },
      "files": [
        {
          "name": "worldborderapi-1.181.2-dev.jar",
          "url": "worldborderapi-1.181.2-dev.jar",
          "size": 23716,
          "sha512": "4474a90a6fbb1ca688fe0efb98b01ca1bc04754eda6799e54da8d4293dcf26ad5da643970bd752e00d2fdfabe2f1f70cb5513ef9cac42e45bca3c6646473eef4",
          "sha256": "e7634463bffbeff8aaa08380202573faf5ab7df33bc87b31de953d64382cd07b",
          "sha1": "dded70f85315cf86d2ada294951922b97c6d0e59",
          "md5": "6df9aab813dc6a49997da287deedeb0c"
        },
        {
          "name": "worldborderapi-1.181.2.jar",
          "url": "worldborderapi-1.181.2.jar",
          "size": 25007,
          "sha512": "43ee006cf16896f26dea8611a594e25c757d0a7b338600d9c8f5b2df277aa914995184c83dbf8491c8d9becf3006af3b4c25f805e3f6744e55638da2ffe89e5c",
          "sha256": "7f59ad1fa0ac0b90c2ec18876bbafe6b3a38ba03f9584ab412abee921d7ad1c2",
          "sha1": "1a5eef3f906080ad89d6b3438877e3071dda7a2e",
          "md5": "0dd8ced1e8a5619db4e4f56689472a39"
        }
      ]
    },
    {
      "name": "apiElementsClasses",
      "attributes": {
        "org.gradle.category": "library",
        "org.gradle.dependency.bundling": "external",
        "org.gradle.jvm.version": 17,
        "org.gradle.libraryelements": "classes",
        "org.gradle.usage": "java-api"
      }
    },

Further while using affected version's gradle prints an information

> No matching variant of com.github.yannicklamprecht:worldborderapi:1.193.0 was found. The consumer was configured to find a component for use during compile-time, compatible with Java 17, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.gradle.category' with value 'apiElements' but:
- Variant 'apiElements' capability com.github.yannicklamprecht:worldborderapi:1.193.0 declares a component for use during compile-time, compatible with Java 17, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, as well as attribute 'org.gradle.category' with value 'library' and the consumer needed a component, as well as attribute 'org.gradle.category' with value 'apiElements'

Overall it makes library undetected in IntelliJ which makes library nearly unusable while using gradle.

To Reproduce Steps to reproduce the behavior:

  1. Create empty gradle project in IntelliJ
  2. Add WorldBorderAPI affected dependency

Expected behavior Library is imported, working and shown in External Libraries

Screenshots image

Desktop (please complete the following information):

Proof of concept

When deleted manually other variants and left only this one which was intiallly on 1.18.1 everything works fine. Proof: https://repo.mcmanhunt.com/#/releases/pl/szczurowsky/worldborderapi

Also works when dependency imported while choosing variant

   compileOnly("com.github.yannicklamprecht:worldborderapi:1.181.1") {
        attributes {
            attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, Usage.JAVA_API))
            attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements::class.java, LibraryElements.JAR))
        }
    }
yannicklamprecht commented 1 year ago

Just use the dev classifier. Due the state that you only use API methods it shouldn't be a problem.

It was something I brought up at paperweight but didn't investigate further.

For further info here is what I brought up https://github.com/PaperMC/paperweight/pull/137 and it resulted in an issue that probably will be fixed in the future. https://github.com/PaperMC/paperweight/issues/177