swiftlang / swiftlang/swift-java

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

Open
#82 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature:wrap-java plugin:swiftpm
Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

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:

  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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SwiftPM command plugin documentation and the existing Java2SwiftPlugin. Define the import-java-jar command around the specified target and Jar file, producing Sources/MySwiftTarget/Java2Swift.config and updating Package.swift as described. Done means the generated configuration covers public Jar classes and swift build can use the wrapped library.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
build-system, cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.