Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Custom Package with Git Dependencies

Discussion in 'Package Manager' started by OloinMilsom, Feb 12, 2019.

  1. OloinMilsom

    OloinMilsom

    Joined:
    Jan 21, 2019
    Posts:
    2
    Using Unity 2018.3.1f1 I am investigating if it's possible to create a dependency in a custom package's package.json to another custom package.

    For example, I created two package.json files like these:

    Dependency

    Code (JavaScript):
    1. {
    2.     "name": "com.test.dependency",
    3.     "displayName": "Test Dependency",
    4.     "version": "0.0.1",
    5.     "unity": "2018.3",
    6.     "description": "bla bla bla",
    7.     "category": "Unity",
    8.     "dependencies": {}
    9. }
    Depender
    Code (JavaScript):
    1. {
    2.     "name": "com.test.depender",
    3.     "displayName": "Test Depender",
    4.     "version": "0.0.1",
    5.     "unity": "2018.3",
    6.     "description": "bla bla bla",
    7.     "category": "Unity",
    8.     "dependencies": {
    9.         "com.test.dependency": "https://github.com/GitUserName/Test.Dependency.git"
    10.     }
    11. }

    I then created a new unity project and added the Depender to the manifest.json:
    Code (JavaScript):
    1. {
    2.     "dependencies": {
    3.         "com.test.depender": "https://github.com/GitUserName/Test.Depender.git",
    4.         ...
    5.     }
    6. }
    Upon opening this project I get the following error:
    Package com.test.depender@https://github.com/GitUserName/Test.Depender.git has invalid dependencies:
    com.test.dependency: Version 'https://github.com/GitUserName/Test.Dependency.git' is invalid. Expected a 'SemVer' compatible value.

    I'm wondering if there's anything I've missed that would get this working. If it is not possible, as the errors would suggest, to have custom dependencies in a package.json file, will this be supported in future?
     
    Last edited: Feb 12, 2019
    mobuni5 and Karnsteiner like this.
  2. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    144
    For security and stability reasons, this is currently not supported, by design. I can't say whether or not this feature will be supported in the future for custom packages, but I expect that no published package hosted by Unity will ever be allowed this since it essentially side-steps any kind of validation/verification of the package.

    What you can do, however, is use a scoped registry (a.k.a. private registry) to publish your custom packages on a registry you control. (See https://forum.unity.com/threads/setup-for-scoped-registries-private-registries.573934/ for more information on how to set this up.)

    Also note that while the packages are embedded in your project or declared as a dependency in your project manifest, they override any package of the same name found as a package dependency during dependency resolution. So, barring the use of a scoped registry, your above setup would work if you explicitly added the Dependency package in your project manifest using a Git URL, and updated your Depender package.json so it did not declare a dependency on the Dependency package or declared it with a version (that would be ignored in favor of the project dependency on Dependency).
     
    OloinMilsom likes this.
  3. Karnsteiner

    Karnsteiner

    Joined:
    Mar 24, 2013
    Posts:
    24
    I might be mistaken, but it seems like Oloin is referring more to a package hosted on his own git repository versus one hosted by Unity. I am also looking at this for splitting up an open source project hosted on github into several smaller packages with one core and the others as optional secondaries requiring core.

    It seems implied that something like this might work based on what forum threads/documentation I've found, but now requires a user to list all dependencies of a package independently in the manifest.json file and won't account for sub-dependencies (two levels deep dependencies or more).

    Package.json
    Code (JavaScript):
    1. {
    2.     "name": "com.test.depender",
    3.     "displayName": "Test Depender",
    4.     "version": "0.0.1",
    5.     "unity": "2018.3",
    6.     "description": "bla bla bla",
    7.     "category": "Unity",
    8.     "dependencies": {
    9.         "com.test.dependency": "1.0.0"
    10.     }
    11. }
    Manifest.Json
    Code (JavaScript):
    1. {
    2.     "dependencies": {
    3.         "com.test.dependency": "https://github.com/GitUserName/Test.Dependency.git",
    4.         "com.test.depender": "https://github.com/GitUserName/Test.Depender.git",
    5.         ...
    6.     }
    7. }
     
    k0dep and Stephen-Hodgson like this.
  4. k0dep

    k0dep

    Joined:
    Jul 21, 2013
    Posts:
    5
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    268
    This is seriously annoyingly nonsense. The usable of package manager is to let us able to share any package with any dependency package and the manager will resolve all dependency automatically. If you don't let us upload all of our package on your server directly then it limit the usability of the manager. We must uselessly include all of our sub package in our own package or else we cannot share it

    If we only develop individually or internally then we don't really need package manager at all. The point is to share the package as a submodule to anyone and anywhere. Scope registry is totally useless and waste of time on your side. We only need git dependency and custom dependency. I really want to ask who was think about this idea and waste all your time? Have you even think about the use case scenario before add this feature?

    We just need a custom dependency. Not a useless workaround like scoped registry unless the scope registry could be resolved from dependency. If we tell people that "you can add our package into package manager" but then "oh but you also need to add this line in this file and these lines in this file and this line in these files" then it become totally pointless to have package manager
     
    turbanov likes this.
  6. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    144
    Hi @Thaina,

    I'm sorry to hear that the Package Manager does not exactly fit your requirements.

    We are still working on putting the required infrastructure, tooling, and publishing flows to enable external contributions to the Package Manager registry. That is why I mentioned setting up a private registry would be the first step in sharing custom packages.

    Setting up your own registry (for instance Verdaccio -
    https://github.com/verdaccio/verdaccio) is actually pretty simple. It's installed using npm, and run using a single command-line. Configuring the Package Manager to use that scoped registry is also not too complicated - an action you need to do once per project so the Package Manager knows where to look in addition to the main registry (see https://docs.unity3d.com/Manual/upm-scoped.html) when it resolves the project's dependencies.

    For example, you could add the following to a project manifest:
    Code (CSharp):
    1. "scopedRegistries": [
    2.     {
    3.       "name": "My Registy",
    4.       "url": "<http(s)-url-to-your-registry>",
    5.       "scopes": [
    6.         "com.thaina"
    7.       ]
    8.     }
    9. ],
    10.  
    and all packages whose name begins with
    com.thaina.
    would be fetched from that registry, which you're free to administer as you wish.
     
  7. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    268
    @maximeb_unity That's the point that I would call it pointless

    The point is, this feature is Package Manager. It was named as "Package Manager" and you can see that every popular package manager, be it NPM or NuGet, has an ability to resolve all of it dependency as first priority. Because if the package can resolve dependency in one machine but failed to resolved in another machine without tweaking configuration, That package would become useless, and also the manager itself would be a totally useless manager

    And to config each and every machine just to use one package is defeating the purpose of using package manager itself. So if any feature want to have be named Package Manager it should have a way to resolve dependency of any depth from the package itself without having people go manage each dependency when they just want to include another package

    People try to include package in their project for their convenience. But you are making this useless package manager that force people to do inconvenience things it defeat the purpose of using Package Manager immediately

    an action I need to do once per project is not acceptable for the feature named Package Manager. It must be an action I need to do once per package. It must be an action that, when I tell some people to include my package. They only really need to just include my package and done, the manager will do everything on its own to resolve every bits of dependency into that person's project, any number of person and any number of project, to have each person need to tweak each project they create just to use my package it a uselessly annoyingly inconvenience loss cost

    Because the usability of the feature named Package Manager is that, I am not the one who use it. There would be many people to use it by installing my package into their project

    This is why I want to ask that, have you ever think about the use case scenario of this feature? Have you ever think about the actual use case scenario of feature named Package Manager ? Who have suggest you to try doing that useless scope registry feature before custom dependency? You trying to present scope registry is telling me that you are all half heartedly in designing the feature named Package Manager. You don't understand the use case of Package Manager at all. Unless the scope registry can be resolved from the package. Which I have trying and it was not

    If you making feature named Package Manager you then must have thought about this. If not you should just name it Unity Registry Package Installer UI not a Package Manager or else it will become a false advertisement
     
    Last edited: May 6, 2019
  8. insominx

    insominx

    Joined:
    Jan 23, 2012
    Posts:
    18
    This seems to be limited to Github due to Topic. Is there a way to make this work elsewhere like off of gitlab?
     
    k0dep likes this.
  9. k0dep

    k0dep

    Joined:
    Jul 21, 2013
    Posts:
    5
    Yes, indeed, the current implementation has limitations associated with GitHub. Now I am working on the development of the whole ecosystem for working with packages regardless of their location, I plan to finish by the end of the month.
     
  10. Rock360

    Rock360

    Joined:
    Oct 26, 2016
    Posts:
    8
    Hi.
    I found an awesome repo and thought it should be shared.
    This plugin looks like a PERFECT solution for me!
    https://github.com/mob-sakai/GitDependencyResolverForUnity

    (From the README)

    This plugin resolves git url dependencies in the package for Unity Package Manager.
    You can use a git url as a package dependency!

    Features
    • Easy to use: just install
    • Resolve git url dependencies in packages
    • Uninstall unused packages that is installed by this plugin
    • Support GitHub, Bitbucket, GitLab, etc.
    • Support private repository
    • Support Unity 2019.1+
    • Support .Net 3.5 & 4.x
    • Update package with a specific tag/branch
    Install
    • Find Packages/manifest.json in your project and edit it to look like this:
    Code (JavaScript):
    1. {
    2.   "dependencies": {
    3.     "com.coffee.git-dependency-resolver": "https://github.com/mob-sakai/GitDependencyResolverForUnity.git#1.0.0",
    4.     ...
    5.   }
    6. }
    • To update the package, change #{version} to the target version. Or, use UpmGitExtension.
     
    zinchencko, turbanov and Northmaen like this.