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.
Apply the plugin
Section titled “Apply the plugin”In build.gradle.kts:
plugins { id("io.scade.gradle.plugins.swiftpm") version "1.4.5"}Configure the Swift package
Section titled “Configure the Swift package”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:
./gradlew assembleSwiftPackageThis does two things:
-
Generates bridging — runs
swift package plugin generate-java-bridgingand adds the output to themainJava source set, so the generated proxy classes compile automatically with the rest of your project. -
Builds the native library — runs
scd archivefor the host platform (macOS, Linux, or Windows, detected automatically) and puts the output inbuild/lib/.
Target platform
Section titled “Target platform”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().
scd options
Section titled “scd options”Pass additional flags to the scd build tool via scdOptions:
swiftpm { path = file("../MySwiftPackage") product = "MySwiftPackage" scdOptions = listOf("--verbose")}scd location
Section titled “scd location”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}Java compatibility
Section titled “Java compatibility”The bridging generator defaults to Java 11. Set javaVersion to match your project’s source compatibility:
swiftpm { path = file("../MySwiftPackage") product = "MySwiftPackage" javaVersion = 8}Full reference
Section titled “Full reference”See Configuration for all available properties and Tasks for the complete task list.