Skip to content

feat(bindings): add Java bindings#4681

Merged
WillLillis merged 2 commits intotree-sitter:masterfrom
ObserverOfTime:java
Dec 8, 2025
Merged

feat(bindings): add Java bindings#4681
WillLillis merged 2 commits intotree-sitter:masterfrom
ObserverOfTime:java

Conversation

@ObserverOfTime
Copy link
Member

@ObserverOfTime ObserverOfTime commented Aug 8, 2025

I believe the Java bindings are now stable enough to include (opt-in) in 0.26.

The parser namespace (by default io.github.tree-sitter) is converted to io.github.treesitter.jtreesitter.parsername
for the package name and main/java/io/github/treesitter/jtreesitter/parsername for the directory.

The pom.xml includes the necessary configuration to publish packages to Maven Central.
However, the user must have a Sonatype account and a GPG key and add 4 secrets to the workflow…
image

Alternatively, we can publish to JitPack which doesn't require any secrets or workflows.
Instead, it needs a jitpack.yml file and the namespace must start with com.github.
Also, end users must add its repository to their build files alongside Maven Central.

@ObserverOfTime ObserverOfTime force-pushed the java branch 4 times, most recently from 07ed427 to f7a90b7 Compare August 9, 2025 12:42
@ObserverOfTime ObserverOfTime force-pushed the java branch 2 times, most recently from 9aad3eb to d20e44f Compare August 12, 2025 08:39
@ObserverOfTime
Copy link
Member Author

Maven Central

Pros

  • End users won't need to add an extra repository to their build files
  • The namespace/package of core parsers will be consistent with jtreesitter

Cons

  • Parser authors will need a Sonatype account and GPG key
  • Requires a new reusable workflow

JitPack

Pros

  • Parsers authors don't need to do anything special
  • Doesn't require a new workflow

Cons

  • Requires an additional generated file
  • End users will need to add an extra repository to their build files
  • The namespace/package of parsers will be inconsistent with jtreesitter

@ObserverOfTime
Copy link
Member Author

I'd like some user opinions regarding the packaging.

/cc @stackoverflow @bioball @Emmeral @maloewe-ona

@Emmeral
Copy link

Emmeral commented Sep 1, 2025

So if I understand this correctly, the actual binaries will not be uploaded to the remote repository but only the bindings class and the user of the bindings needs to supply the binaries themself?

@Emmeral
Copy link

Emmeral commented Sep 1, 2025

I'd like some user opinions regarding the packaging.

I don't have a specific opinion on the Maven Central vs JitPack topic. For my use case, I would need to modify the pom in both cases.

@sogaiu
Copy link
Collaborator

sogaiu commented Sep 21, 2025

The cons of Maven Central seem significantly worse to me than those for JitPack.

@ObserverOfTime
Copy link
Member Author

Perhaps, but something like this is not possible in JitPack:

So if I understand this correctly, the actual binaries will not be uploaded to the remote repository but only the bindings class and the user of the bindings needs to supply the binaries themself?

@ObserverOfTime
Copy link
Member Author

I'm leaning towards Maven Central after all since it allows us to fully control the release process.

@sogaiu
Copy link
Collaborator

sogaiu commented Sep 22, 2025

Just to clarify:

Parser authors will need a Sonatype account and GPG key

Does this mean that individual grammar / parser authors need to setup and maintain these bits over the long term then?

@ObserverOfTime
Copy link
Member Author

They also need (if they want) to set up and maintain tokens for npmjs, pypi, and crates. The only extra here is the GPG key.

@sogaiu
Copy link
Collaborator

sogaiu commented Sep 23, 2025

I wonder about the practicality of this kind of arrangement over the longer term. It seems to me that many a grammar / parser author has lost interest after a certain point. In a nicer world, may be there would be two or more folks looking after a given grammar / parser for robustness (though OFC that's a larger attack surface as well...).

I've been ok with looking after a few grammars, but I have no interest in setting up and properly looking after additional accounts and/or tokens (and thereby becoming a slightly more juicier target). Perhaps this is a minority position though.

@ObserverOfTime
Copy link
Member Author

Although, now that I think about it, those can also be installed directly from git.
That is sort of possible with JitPack but not (easily) with Maven Central.

Copy link
Member

@amaanq amaanq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, I don't know Java but I assume this has been tested with a grammar locally and works.

@ObserverOfTime ObserverOfTime force-pushed the java branch 2 times, most recently from cada7b3 to 129b25b Compare September 25, 2025 16:58
@clason clason modified the milestones: 0.26, 0.27 Sep 28, 2025
@ObserverOfTime ObserverOfTime modified the milestones: 0.27, 0.26 Oct 3, 2025
Copy link
Member

@WillLillis WillLillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming local tests are working on your end, let's give this a spin.

Copy link
Contributor

@clason clason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation under https://tree-sitter.github.io/tree-sitter/cli/init.html#the-bindings-field

(which is also missing the Zig bindings!)

(and shouldn't list the Kotlin bindings until they're actually available)

@WillLillis WillLillis merged commit d861e2b into tree-sitter:master Dec 8, 2025
19 checks passed
@ObserverOfTime ObserverOfTime deleted the java branch December 8, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants