如何使用Swift Package Manager将SwiftLint与iOS应用程序集成? [英] How to integrate SwiftLint with an iOS app using Swift Package Manager?

查看:53
本文介绍了如何使用Swift Package Manager将SwiftLint与iOS应用程序集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode 11(测试版5)中创建一个新的iOS应用,我想尝试使用Swift Package Manager代替CocoaPods来管理依赖项.

I'm creating a new iOS app in Xcode 11 (beta 5) and I'd like to try using Swift Package Manager instead of CocoaPods for managing dependencies.

使用SwiftLint和CocoaPods时的常见模式是添加SwiftLint作为依赖项,然后添加一个构建阶段以执行 $ {PODS_ROOT}/SwiftLint/swiftlint ;这样,所有开发人员最终都会使用相同版本的SwiftLint.

A common pattern when using SwiftLint and CocoaPods is to add SwiftLint as a dependency and then add a build phase to execute ${PODS_ROOT}/SwiftLint/swiftlint; this way all developers end up using the same version of SwiftLint.

如果我尝试将SwiftLint添加为Xcode中的SwiftPM依赖项,则会禁用我需要的可执行目标:

If I try to add SwiftLint as a SwiftPM dependency in Xcode, the executable target that I need is disabled:

我可以通过创建一个没有产品或目标的虚拟 Package.swift 并在构建阶段运行 swift run swiftlint 来伪造它,但是感觉很hacky,奇怪:

I was able to fake it by creating a dummy Package.swift with no products or targets and running swift run swiftlint in my build phase, but it feels hacky and weird:

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "dummy-package",
    products: [],
    dependencies: [
        .package(url: "https://github.com/realm/SwiftLint.git", from: "0.34.0")
    ],
    targets: []
)

有没有不创建虚拟包的方法吗?还是Swift Package Manager并不是适合此特定用例的合适工具?

Is there a way do this without creating a dummy package? Or is Swift Package Manager just not the right tool for this particular use case?

推荐答案

所有滥用iOS代码依赖管理器来运行构建工具的方法都是很怪异的.

All methods of abusing iOS code dependency managers to run build tools are hacky and weird.

版本兼容SPM的工具依赖项的正确方法是使用 Mint:安装并运行Swift CLI的程序包管理器包.另请参阅更好的iOS项目:如何管理工具用薄荷.

The correct way to version SPM-compliant tool dependencies is to use Mint: A package manager that installs and runs Swift CLI packages. See also Better iOS projects: How to manage your tooling with mint.

这篇关于如何使用Swift Package Manager将SwiftLint与iOS应用程序集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆