Description
The SwiftPM build tool plugin Java2SwiftPlugin
wraps up the specified set of Java classes so they can be used from Swift. It requires a configuration file containing the mapping from specific Java canonical class names to their Swift type names. However, we'd like to make it easier to get started by importing a Jar file into a Swift target, scanning the Jar file for any public classes and generating the Java2SwiftPlugin
configuration file.
A SwiftPM command plugin would be a reasonable approach here. Essentially, it would take a SwiftPM target name and Jar file and update the package to wrap the public classes from that Jar file. It could be written as:
swift package import-java-jar MySwiftTarget MyJavaLib.jar
This command would produce two outputs:
- A file
Sources/MySwiftTarget/Java2Swift.config
that includes the Jar file in the class path and lists the mappings for all of the public classes within that Jar file. - An updated
Package.swift
that contains a package dependency on swift-java and applies the Java2SwiftPlugin to the MySwiftTarget.
The goal should be that one can "ingest" a Java library with one command, then swift build
to get access to that library from Swift.