gpt4 book ai didi

git - 如何从 GitHub 获取 pub 作为依赖

转载 作者:太空狗 更新时间:2023-10-29 13:09:33 25 4
gpt4 key购买 nike

我正在学习 Dart,但是我发现了一个问题:

我想添加 widget.dart从它的 GitHub 存储库中打包作为我项目的依赖项。但是在 pub.dartlang.org 中有一个非常旧的版本,它需要过时的 Web UI。有谁知道,如何从 GitHub 存储库获取发布(并像从 pub.dartlang.org 那样安装它)?

我在 Windows 和 Dart 编辑器上使用 GitHub。


更新:我尝试将其添加到依赖项中并以经典方式运行“pub get”:

dependencies:
widget:
git: git@github.com:dart-lang/widget.dart.git

但是它返回这个错误:

--- 30.1.2014 15:35:27 Running pub get ... ---
Pub get failed, [1] Resolving dependencies...
Cannot get widget from Git (git@github.com:dart-lang/widget.dart.git).
Please ensure Git is correctly installed.
e:\b\build\slave\dart-editor-win-stable\build\dart\sdk\lib\_internal\pub\lib\src\source\git.dart 42 GitSource.downloadToSystemCache.<fn>
dart:isolate _RawReceivePortImpl._handleMessage

This is an unexpected error. Please run

pub --trace 'get'

and include the results in a bug report on http://dartbug.com/new.

** Warning: Application may fail to run since packages did not get installed.Try running pub get again. **

最佳答案

pubspec.yaml中添加依赖

在文本模式下编辑 pubspec.yaml

dependencies:
widget:
git: git@github.com:dart-lang/widget.dart.git

使用助手

如果你在 DartEditor 中打开 pubspec.yaml 文件,你会得到一个很好的助手

  1. 点击添加...
  2. 输入包名:'widget'
  3. 将查找 Sourcehosted 更改为 git
  4. Git ref: 设置为 git@github.com:dart-lang/widget.dart.git

附加信息:

  • 您可以在小部件的 GitHub 存储库 name: widget 下的文件 pubspec.yaml 中查找依赖项名称
  • 您可以从 SSH clone URL 下的 GitHub 存储库复制 git 路径(在“下载 ZIP”按钮上方)

编辑
要完成这项工作,您需要在本地系统上安装 git 命令行客户端。

您可以手动下载存储库

git clone git@github.com:dart-lang/widget.dart.git

并添加如下依赖

dependencies:
widget:
git: ../widget.dart
# path: ../widget.dart # would work too

或者,您可以从 GitHub 下载存储库(下载为 ZIP),将其解压缩到本地驱动器并使用 path: 依赖项,例如

dependencies:
widget:
path: ../widget.dart

前提是您将 ZIP 解压缩到包的同级文件夹中。

另见 https://www.dartlang.org/tools/pub/dependencies#git-packages

关于git - 如何从 GitHub 获取 pub 作为依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21458598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com