【问题标题】:How do i use Composer to install a package without a version (only master)我如何使用 Composer 安装没有版本的包(仅限 master)
【发布时间】:2014-02-11 06:15:33
【问题描述】:

我是作曲家的新手,我正在尝试通过作曲家更新安装以下库

https://github.com/neitanod/forceutf8

据我了解,我的 composer.json 看起来像这样

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "forceutf8/forceutf8": "master"
    }
}

Bt 出于某种原因(因为我认为 forceutf8 没有版本)它因错误而停止,其余所有安装正确,我得到的错误是

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package forceutf8/forceutf8 could not be found in any version, there may be a typo in the package na
me.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. 

我也尝试了以下版本,但仍然没有运气

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "name": "career/skillquest",
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/neitanod/forceutf8"
      }
    ],
    "require": 
      {
        "forceutf8/forceutf8": "dev-master",
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16"
      }
}

问题是它需要是

"neitanod/forceutf8": "dev-master"

不是

"forceutf8/forceutf8": "master"

【问题讨论】:

    标签: composer-php


    【解决方案1】:

    首先,你的名字是错误的:forceutf8/forceutf8 正确的名字是:neitanod/forceutf8

    Composer 为每个看起来不像版本号的分支名称添加前缀“dev-”,并为看起来像版本号的分支名称添加后缀“-dev”。

    示例:分支“master”称为“dev-master”,分支“feature”称为“dev-feature”。分支“1.0.x”被称为“1.0.x-dev”。

    所以这部分是错误的:

    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "forceutf8/forceutf8": "master"
    }
    

    正确的版本是:

    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "neitanod/forceutf8": "dev-master"
    }
    

    现在要求没有标记版本的分支并不是最好的事情,因为这些信息非常不稳定 - 任何新的提交都可能破坏事情,并且准确地指向您想要使用的提交并不容易。为了防止这种情况发生,Composer 默认不加载这些开发分支,而只会加载稳定版本。您必须启用加载开发版本:

    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "neitanod/forceutf8": "dev-master@dev"
    }
    

    “@dev”标志允许加载上述版本的开发版本(在本例中是一个分支,但“1.0.0@dev”将以相同的方式工作,允许所有(包括开发)1.0 版本.0,像“1.0.0-alpha”,但也是稳定的“1.0.0”)。

    请注意,您还可以通过使用“最低稳定性”来允许所有依赖项的开发版本,但不建议这样做,因为它会根据版本要求加载所有依赖项的开发版本。在您的情况下,您将只获取 monolog 1.7 分支的最新开发版本,但这可能足以使曾经稳定的软件进入损坏状态。

    【讨论】:

    • 但这并不识别 git url 吗?
    • 我假设该软件包已在 packagist.org 上注册,但目前该站点似乎已关闭。因此,您将无法更新任何内容。
    • 非常感谢您的解释:'Composer 为每个看起来不像版本号的分支名称添加前缀“dev-”,并为分支添加后缀“-dev”看起来像版本号的名称。我鄙视 Composer 中的这种语法。
    【解决方案2】:

    composer.json中:

    {
        "name": "example/example-app",
        "repositories": [
          {
            "type": "vcs",
            "url": "https://github.com/neitanod/forceutf8"
          }
        ],
        "require": 
          {
            "neitanod/forceutf8": "dev-master",
            "raven/raven": "0.7.1",
            "monolog/monolog": "1.7.*",
            "smarty/smarty": "3.1.16"
          }
    }
    

    【讨论】:

    • 能否请您将完整的 json 文件与其他包一起添加,我尝试添加此文件但未能获得所需的文件格式
    • 那么 forceutf8 软件在哪里?
    • 抱歉,我忘记在 require 中添加 'forceutf8'。固定
    • 试过但还是不行我得到问题1-在任何版本中都找不到请求的包forceutf8/forceutf8,包名可能有错字。
    • require 中写 "neitanod/forceutf8" : "dev-master" 而不是 "forceutf8/forceutf8": "dev-master "
    【解决方案3】:

    很简单!你应该在控制台输入:

    composer require blablabla@thepackage dev-master
    

    【讨论】:

      【解决方案4】:

      您必须在 composer.json 文件中指定版本名称。 只需在 https://packagist.org/

      找到任何可使用 Composer 安装的软件包

      在那里搜索包名,你会找到版本名。 这是您想要的包的链接:https://packagist.org/packages/neitanod/forceutf8

      【讨论】:

        猜你喜欢
        • 2017-04-16
        • 2018-12-21
        • 2014-05-27
        • 1970-01-01
        • 2013-10-02
        • 2015-05-15
        • 2019-03-16
        • 2020-05-03
        • 1970-01-01
        相关资源
        最近更新 更多