Skip to content

SwiftPM command plugin to ingest a Jar file into a SwiftPM target to wrap those Java classes #82

Open
@DougGregor

Description

@DougGregor

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:

  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions