Search Unity

Question Custom dependencies

Discussion in 'Package Manager' started by aarware, Oct 14, 2022.

  1. aarware

    aarware

    Joined:
    Feb 19, 2015
    Posts:
    5
    I am having in issue trying to include one custom package as a dependency in another that I have created.
    The error I receive is
    Version 'https://github.com/[-----].git' is invalid. Expected a 'SemVer' compatible value. [NotFound].

    Both are custom packages I created and can be imported just fine alone and work but when I add one as a decency in the other's package.json I receive the error above. I am running unity version 2021.3.4f1 as well.

    Does the package.json not support custom packages from remote git repos?

    This is the set up for the two packages, the second including the first as a dependency.

    Code (JavaScript):
    1. {
    2.   "name": "com.aarware.scripts.templates",
    3.   "version": "1.0.1",
    4.   "displayName": "Script Templates",
    5.   "description": "",
    6.   "unity": "2021.3",
    7.   "unityRelease": "4f1",
    8.   "keywords": [],
    9.   "author": {
    10.     "name": "",
    11.     "email": "",
    12.     "url": ""
    13.   }
    14. }
    Code (JavaScript):
    1. {
    2.   "name": "com.aarware.core",
    3.   "version": "1.0.0",
    4.   "displayName": "Core",
    5.   "description": "",
    6.   "unity": "2021.3",
    7.   "unityRelease": "4f1",
    8.   "keywords": [],
    9.   "author": {
    10.     "name": "",
    11.     "email": "",
    12.     "url": ""
    13.   },
    14.  
    15.   "dependencies": {
    16.     "com.aarware.scripts.templates": "https://github.com/......git"
    17.   }
    18. }
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    You can include a dependency to your package like so:

    Code (CSharp):
    1.   "dependencies": {
    2.     "com.aarware.scripts.templates": "1.0.1"
    3.   }
    There's no need (and I believe it's not even possible because there is no way to version git repositories) to include git repositories as dependency of a package. You can add packages from github directly using the project's manifest.json. You could try to do that and then use the above as dependency.

    Otherwise you have to have the Script Templates package added manually to the project first, otherwise it will not be found by the other package since it is not in the package registry. The proper way to do this would be with a custom registry so you can make your versioned packages available from there.

    Anyhow, you can still sync your Script Templates package with git by cloning it to some directory on your computer, then in Package Manager choose "Add from disk" and locate the package.json in that directory. Any change to the package you can then commit and push to github using the regular git(hub) workflow. That way you don't have to setup a registry, especially if you work alone or in a small team that works well enough.
     
  3. aarware

    aarware

    Joined:
    Feb 19, 2015
    Posts:
    5
    "packagename" : "version" is only correct for packages registered with unity so what you have list wont work.

    What I have is the correct syntax for custom packages when including via the main manifest and yes git reop works, I did how ever see some docs showing the same syntax in side the package json, also there is no way your example would work with out the dependences being local or registered with unity, the package manager needs to know where to pull it from and with the value only being a version number it would try to pull from unity.

    https://docs.unity3d.com/Manual/upm-git.html
     
  4. aarware

    aarware

    Joined:
    Feb 19, 2015
    Posts:
    5
    Ok so I missed in that doc, it does state clearly it only will work in the manifest, which is a bummer, the point was to not have duplicate scripts in both or for the one to have errors because it could not find the definition for a few scripts it relies on if the other package is not imported. So sounds like the only option would be to create a custom registry if I wanted it to work as intended.
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Not true. I have this in one of my packages which depends on my "core" package:
    Code (CSharp):
    1.   "dependencies": {
    2.     "com.codesmile.core": "0.1.0",
     
  6. aarware

    aarware

    Joined:
    Feb 19, 2015
    Posts:
    5
    Your missing the point, I don't want any of them local or require the need to include both manually, it kind of defeats the purpose. It would be cool if the package's dependencies worked with git urls the same as the main manifest does.

    The idea was to have multiple libraries and not having to worry about importing extra dependency manually that may be needed or having to know it may need to first be stored locally. So if anyone else imports one of the packages they would not get errors because of a missing dependency with no good way to enforce it or explain its needed before had. So as it appears a custom repository is needed to achieve this or the packages need to be published to unity so its fully automated.

    For what your saying I know and would be fine if I only intend to use it and I know I could add an explanation into the read.me explaining that there is another repo required but that is not ideal and could be missed, so for my use case I will just have to combined the two so there is no issue/confusion for others that might use it.

    Thanks for the feedback.
     
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    I understand, for a (bigger) company it's essential to have your own package registry to support dependencies to custom packages.

    You're not trying to do this for the Asset Store though, right? Because UAS packages still are regular .unitypackage packages. I didn't realize that until I've already had my package dependency structure set up.
     
  8. aarware

    aarware

    Joined:
    Feb 19, 2015
    Posts:
    5
    Yeah this is just personal stuff I was just to share and make it as easy as possible, and the new package manage is really cool for all this, just sucks it does not allow for the dependencies in the same fashion as the main manifest, o well there is always ways to go about it.