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

时间:2021-08-02 02:45:00

Using Xcode 9 and Swift 4 as well as vapor heroku push / vapor heroku init, I receive:

使用Xcode 9和Swift 4以及蒸汽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

In the Package.swift file it says:

在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"])
    ]
)

Other than that it is literally the initial api template project. What am I missing? Help is very appreciated.

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

3 个解决方案

#1


11  

The project template was recently updated to require Swift 4, but the Heroku buildpack still installs Swift 3.1.1 by default. Until the template is updated to resolve this situation, do this:

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

  1. Create a file called .swift-version in your project root with 4.0 inside.
  2. 在项目根目录中创建一个名为.swift-version的文件,其中包含4.0。
  3. Commit and push to Heroku.
  4. 提交并推送到Heroku。

The buildpack will now install Swift 4 and your project will compile.

buildpack现在将安装Swift 4,您的项目将编译。

Update (2017-11-13)

I have updated the buildpack, therefore the steps above are no longer necessary.
New applications and pushes without a pinned version will use Swift 4.0.2.

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

#2


2  

Above answer is perfect, I just try to simplify for those who might get confused (like me :D) and having question How to ?

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

Go to your project root directory.

转到项目根目录。

  1. Create swift-version like
    • $ touch .swift-version
    • $ touch .swift-version
  2. 像$ touch .swift-version一样创建swift-version
  3. Open that file

    打开该文件

    • $ open .swift-version

      $ open .swift-version

      write 4.0

      写4.0

  4. save that file

    保存该文件

Done :)

完成:)

#3


0  

Firstly install swift 4.0, then set it as builder.

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

swiftenv install 4.0
swiftenv local 4.0

ref: https://github.com/kylef/heroku-buildpack-swift

ref:https://github.com/kylef/heroku-buildpack-swift

#1


11  

The project template was recently updated to require Swift 4, but the Heroku buildpack still installs Swift 3.1.1 by default. Until the template is updated to resolve this situation, do this:

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

  1. Create a file called .swift-version in your project root with 4.0 inside.
  2. 在项目根目录中创建一个名为.swift-version的文件,其中包含4.0。
  3. Commit and push to Heroku.
  4. 提交并推送到Heroku。

The buildpack will now install Swift 4 and your project will compile.

buildpack现在将安装Swift 4,您的项目将编译。

Update (2017-11-13)

I have updated the buildpack, therefore the steps above are no longer necessary.
New applications and pushes without a pinned version will use Swift 4.0.2.

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

#2


2  

Above answer is perfect, I just try to simplify for those who might get confused (like me :D) and having question How to ?

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

Go to your project root directory.

转到项目根目录。

  1. Create swift-version like
    • $ touch .swift-version
    • $ touch .swift-version
  2. 像$ touch .swift-version一样创建swift-version
  3. Open that file

    打开该文件

    • $ open .swift-version

      $ open .swift-version

      write 4.0

      写4.0

  4. save that file

    保存该文件

Done :)

完成:)

#3


0  

Firstly install swift 4.0, then set it as builder.

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

swiftenv install 4.0
swiftenv local 4.0

ref: https://github.com/kylef/heroku-buildpack-swift

ref:https://github.com/kylef/heroku-buildpack-swift