How to push Vapor 2 Swift 4 project to Heroku

Viewed 894

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

-----> 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:

// 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.

3 Answers

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:

  1. Create a file called .swift-version in your project root with 4.0 inside.
  2. Commit and push to Heroku.

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

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.

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

Go to your project root directory.

  1. Create swift-version like
    • $ touch .swift-version
  2. Open that file

    • $ open .swift-version

      write 4.0

  3. save that file

Done :)

Related