简体   繁体   English

我可以为不同的环境使用不同版本的包吗?

[英]Can I use different versions of a package for different environments?

I have a project where I need to use SQLite in a local environment but Postgres on a normal server.我有一个项目,我需要在本地环境中使用 SQLite,但在普通服务器上使用 Postgres。

Unfortunately, there is no SQLite adapter for Ecto 3 yet, forcing me to keep the Ecto and some related packages at 2.x , which caused some problems such as this one: Ecto 2.0 SQL Sandbox Error on tests不幸的是,目前还没有用于 Ecto 3 的 SQLite 适配器,迫使我将 Ecto 和一些相关包保留在2.x ,这导致了一些问题,例如: Ecto 2.0 SQL Sandbox Error on testing

I wonder if it would be possible to specify two different versions of Ecto and thus dependencies for the environments :local and :prod .我想知道是否可以指定两个不同版本的 Ecto 以及环境的依赖关系:local:prod Currently it seems impossible since there is only one lockfile per project.目前这似乎是不可能的,因为每个项目只有一个锁文件。 The only way to achieve it seems to be to store two different lockfiles in the project directory?实现它的唯一方法似乎是在项目目录中存储两个不同的锁文件? eg https://elixirforum.com/t/only-fetch-deps-compatible-for-a-specific-version-of-elixir/16213例如https://elixirforum.com/t/only-fetch-deps-compatible-for-a-specific-version-of-elixir/16213

I haven't tried it in depth, but maybe changing the mix.exs file like this would help:我还没有深入尝试过,但也许像这样更改 mix.exs 文件会有所帮助:

defmodule YourProject.MixProject do
  use Mix.Project

  def project do
    [
      app: :your_project,
      version: "0.1.0",
      elixir: "~> 1.7",
      start_permanent: Mix.env() == :prod,
      deps: deps(Mix.env()),
      lockfile: lockfile(Mix.env())
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  defp lockfile(:local), do: "mix-local.lock"
  defp lockfile(_), do: "mix.lock"

  # Run "mix help deps" to learn about dependencies.
  defp deps(:local) do
     [{:ecto, "~> 2.0"}]
  end

  defp deps(_) do
     [{:ecto, "~> 3.0"}]
  end
end

Both the lockfile and deps are different for the :local environment. :local环境的 lockfile 和 deps 是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个软件包名称可用于针对不同Android版本的应用吗? - Can one package name be used for apps targeting different versions of Android? 在emacs中使用不同的软件包存储库 - use different package repository in emacs 如果两个 python 包具有不同版本的 package 依赖关系怎么办? - What if two python packages have different versions of package dependencies? CMake 查找具有不同版本的多个包的特定 package (NCurses) - CMake find specific package of multiple packages with different versions (NCurses) 在同一环境下使用不同版本的python包 - Use different version of python package in the same environment 在不同环境中使用 package 的正确方法是什么? - What is the correct way to use a package on different environment? 在不同的本地 npm 包中使用本地 npm 包 - Use local npm package within a different local npm package 如何在不同的计算机上显示一个Flat Package(.pkg)图标? - How can I give a Flat Package (.pkg) an icon which is seen on different computers? 如何告诉caret包从默认的其他位置加载其依赖项? - How can I tell caret package to load its dependencies from a different location other than default? 是否可以包含两个不同的java包并使用它们的API? - Is it possible to include two different java package and use their API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM