Skip to content

Setup

This guide covers applying the base plugin (io.scade.gradle.plugins.swiftpm) to a Java or Kotlin Gradle project. For Android projects, see Android.

In build.gradle.kts:

plugins {
id("io.scade.gradle.plugins.swiftpm") version "1.4.5"
}

Add a swiftpm { } block with the path to your Swift package and the product name to build:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
}

path must point to the directory containing Package.swift. product must be the name of a dynamic library product in that package.

Run the assemble task to build the Swift package:

Terminal window
./gradlew assembleSwiftPackage

This does two things:

  1. Generates bridging — runs swift package plugin generate-java-bridging and adds the output to the main Java source set, so the generated proxy classes compile automatically with the rest of your project.

  2. Builds the native library — runs scd archive for the host platform (macOS, Linux, or Windows, detected automatically) and puts the output in build/lib/.

By default the plugin targets the current host OS. To target a specific platform or pass a custom toolchain:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
platforms = listOf(
TargetPlatform.macOS()
)
}

Supported platforms for the base plugin: TargetPlatform.macOS(), TargetPlatform.Linux(), TargetPlatform.Windows().

Pass additional flags to the scd build tool via scdOptions:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
scdOptions = listOf("--verbose")
}

The plugin expects scd to be installed at its default location (~/Library/Developer/Scade/Toolchains/scd/bin/scd). To use a different binary:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
scd = file("/usr/local/bin/scd")
}

To have the plugin download and keep scd up to date automatically:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
scdAutoUpdate = true
}

The bridging generator defaults to Java 11. Set javaVersion to match your project’s source compatibility:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
javaVersion = 8
}

See Configuration for all available properties and Tasks for the complete task list.