dart path dependencies not working (across multiple projects)
我试图在 dart 中创建一个"库"类型的项目,然后从另一个项目中"依赖"该库(全部使用 yaml 文件的路径依赖功能)。我知道如果我托管我的库或使用 GIT,我可能能够让依赖项工作,但我也不想这样做,因为我觉得基于纯文件系统的依赖项应该是一个"不"脑筋急转弯"。
所以,不用多说,这是我的情况。我有一个非常简单的基于 web_ui 的 dart 库/项目,其中包含两个文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | esrvdartui.dart --------------- library esrvdartui; import 'dart:html'; import 'package:web_ui/web_ui.dart'; part 'esrvradiobutton.dart'; esrvradiobutton.dart -------------------- part of esrvdartui; class ESrvRadioButton extends RadioButtonInputElement { ESrvRadioButton () { } } |
然后我创建了另一个非常小的/简单的基于 web_ui 的项目,名为"ExampleForm",它想使用我上面的 esrvdartui 项目。这两个项目都存在于相同的目录结构中。我的 ExampleForm 项目包含以下 yaml 文件:
1 2 3 4 5 6 7 8 9 10 | pubspec.yaml ------------ name: ExampleForm description: A sample WebUI application dependencies: js: any browser: any web_ui: any esrvdartui: path: ../esrvdartui |
无论我在上面的 yaml 文件中将路径设置为什么,我都不会看到我的 ExampleForm 项目下面的 web\\\\\\\\packages 目录被我的来自 esrvdartui 项目的文件更新,因此,我无法使用使用基于文件的依赖方法在我的库中的文件,因为我的 ExampleForm 项目的构建失败。
"Pub install" 不会抱怨上面的路径,当我使用绝对路径时它不会抱怨,所以我知道 "Pub install" 看到我的依赖项目。它只是不会为我复制那些该死的文件。
有什么想法吗?
我的 ExampleForm 的 pubspec.lock 文件是:
# 由 pub 生成
# 见 http://pub.dartlang.org/doc/glossary.html#lockfile
{"packages":{"logging":{"version":"0.5.0 1","source":"hosted","description":" logging"},"source_maps":{"version":"0.5.0 1","source":"hosted","description":"source_maps" },"unittest":{"version":"0.5.0 1","source":"hosted","description":"unittest"},"pathos":{"version":"0.5.0 1","source":"hosted","description":"pathos"},"analyzer_experimental":{"version":"0.4.7 1","source":"hosted","description":"analyzer_experimental"},"web_ui":{ "version":"0.4.6 1","source":"hosted","description":"web_ui"},"js":{"version ":"0.0.21","source":"hosted","description":"js"},"csslib":{"version":"0.4.3","source":"hosted","description":"csslib"},"esrvdartui":{"version":"0.0.0 ","source":"path","description":{"relative":false,"path":"C:/Users/Jason/dart/esrvdartui" }},"html5lib":{"version":"0.4.3","source":"hosted","description":"html5lib"},"args":{"版本":"0.5.0 1", "source":"hosted","description":"args"},"browser":{"version":"0.5.0 1","source ":"hosted","description":"browser"},"meta":{"version":"0.5.0 1","source": "托管","描述":"元"}}}
我的 esrvdartui 的 pubspec.lock 文件是:
由酒馆生成
见 http://pub.dartlang.org/doc/glossary.html#lockfile
{"packages":{"meta":"version":"0.5.0 1","source":"hosted","description": "meta"},"browser":{"version":"0.5.0 1","source":"hosted","description":"browser "},"args":{"version":"0.5.0 1","source":"hosted","description":"args"} ,"html5lib":{"version":"0.4.3","source":"hosted","description":"html5lib"},"analyzer_experimental ":{"version":"0.5.0 1","source":"hosted","description":"analyzer_experimental"},"csslib": {"version":"0.4.3","source":"hosted","description":"csslib"},"web_ui":{"version ":"0.4.6 1","source":"hosted","description":"web_ui"},"pathos":{"version": "0.5.0 1","source":"hosted","description":"pathos"},"js":{"version":"0.0 .22","source":"hosted","description":"js"},"source_maps":{"version":"0.5.0 1","source":"hosted","description":"source_maps"},"unittest":{"version":"0.5.0 1","源":"托管","描述":"unittest"},"loggi ng":{"version":"0.5.0 1","source":"hosted","description":"logging"}}}
我终于得到了这个工作,但在我的一生中,我无法在任何地方找到这个文档。您所要做的就是在 Dart IDE 中创建一个项目。然后,在该项目中创建一个名为 "lib" 的顶级文件夹(清除除顶级 "packages" 文件夹之外的所有其他目录)。现在,创建您的主库的 .dart 文件。我们称之为"mylibrary.dart"。该文件的内容如下所示:
mylibrary.dart
1 2 3 4 5 | library mylibrary; import 'dart:json'; part 'src/libraryfile1.dart'; |
现在,在 "lib" 下创建一个子目录,将库的源文件放入其中。这实际上可以命名为任何东西,但我选择将其命名为"src"。将您的 libraryfile1.dart 文件放在那里,它应该看起来像这样:
src/libraryfile1.dart
1 2 3 4 | part of hix_lib; . . . |
所有的导入语句都应该放在你的顶级主库文件中:mylibrary.dart.
现在,在您希望在其中使用此基于文件的库的项目中,您必须将"mylibrary"添加到项目的 pubspec.yaml 文件中并选择:"Source: path"。在我的机器上,因为所有项目都在同一个目录中,所以我的路径只是指向:../mylibrary
这就是所有要做的事情!!!!!!