如何将Vapor 2 Swift 4项目推向Heroku

时间:2017-10-05 00:36:57

标签: swift heroku xcode9 vapor

使用Xcode 9和Swift 4以及vapor heroku push / vapor heroku init,我收到:

-----> Swift app detected
Cloning into 'swiftenv'...
Swift 3 Heroku Installer
  Version: 3.1.1
  Operating System: ubuntu1404
 Installing Swiftenv
Cloning into '/app/.swiftenv'...
 Installing Swift
Downloading https://swift.org/builds/swift-3.1.1-release/ubuntu1604/swift-3.1.1-RELEASE/swift-3.1.1-RELEASE-ubuntu16.04.tar.gz
/tmp/swiftenv-3.1.1- /tmp/build_d
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
/tmp/build_d
3.1.1 has been installed.
✅  Done
-----> Installing clang-3.7.0
precompile
-----> Building Package ... this will take a while
swift-build: error: Package requires minimum Swift tools version 4.0.0. Current Swift tools version is 3.1.0
 !     Push rejected, failed to compile Swift app.
 !     Push failed

Package.swift文件中,它说:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "name",
    products: [
        .library(name: "App", targets: ["App"]),
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.1.0")),
        .package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.2.0")),
    ],
    targets: [
        .target(name: "App", dependencies: ["Vapor", "FluentProvider"],
                exclude: [
                    "Config",
                    "Public",
                    "Resources",
                ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App", "Testing"])
    ]
)

除此之外,它实际上是最初的api模板项目。我错过了什么?非常感谢帮助。

3 个答案:

答案 0 :(得分:11)

项目模板最近更新为需要Swift 4,但Heroku buildpack默认仍安装Swift 3.1.1。在更新模板以解决此问题之前,请执行以下操作:

  1. 在项目根目录中创建名为.swift-version的文件,其中包含4.0
  2. 提交并推送到Heroku。
  3. buildpack现在将安装Swift 4,你的项目将编译。

    更新(2017-11-13)

    我已更新buildpack,因此不再需要上述步骤 没有固定版本的新应用程序和推送将使用Swift 4.0.2。

答案 1 :(得分:3)

以上答案是完美的,我只是试图简化那些可能会感到困惑的人(比如我:D)并且有问题怎么样?

转到项目根目录。

  1. 创建swift-version
    • $ touch .swift-version
  2. 打开该文件

    • $ open .swift-version

      写4.0

  3. 保存该文件

  4. 完成:)

答案 2 :(得分:0)

首先安装swift 4.0,然后将其设置为构建器。

swiftenv install 4.0
swiftenv local 4.0

参考:https://github.com/kylef/heroku-buildpack-swift