javabazelbuckpantsskylark

How do I include a Skylark configuration parser in my application?


I like the idea of configuring my Java application with restricted Python code. This restrained Python configuration language goes by the name of Skylark. I found a Go library for Skylark support, but I need a Java one.

Which maven artifact from the bazel project or buck project can I add to my pom.xml dependencies section to get Skylark support library?


Solution

  • Until #2367 is resolved, the following worked for me. Build Skylark_deploy.jar with Bazel and add it to your Maven project as a system dependency. This results in your classpath being a mess, essentially, but it is quick to set up and enables practical experimentation.

    Warning: Skylark has not yet stabilized its API, so anything under com.google.devtools is subject to unannounced change.

    Build Skylark_deploy.jar with Bazel

    git clone git@github.com:bazelbuild/bazel.git --depth 1
    cd bazel
    bazel build //src/main/java/com/google/devtools/skylark:Skylark
    bazel build //src/main/java/com/google/devtools/skylark:Skylark_deploy.jar
    

    Check that it works, either of the two command below should start Skylark REPL

    bazel-bin/src/main/java/com/google/devtools/skylark/Skylark
    java -jar bazel-bin/src/main/java/com/google/devtools/skylark/Skylark_deploy.jar
    

    The Skylark_deploy.jar is currently 9.4MiB in size.

    Add it to your Maven project as a system dependency

    <systemPath>${project.basedir}/lib/Skylark_deploy.jar</systemPath>
    

    Or use Gradle

    compile files('lib/Skylark_deploy.jar')
    

    See https://github.com/bazelbuild/bazel/blob/0f99c3cc0b7b82e198c8f365254493fc4713edcd/src/main/java/com/google/devtools/starlark/cmd/Starlark.java for initial inspiration. (Skylark was renamed to Starlark at one point.)

    See https://github.com/google/copybara/blob/d4f9bd37ddf6eb51f1072ffb4e61332f7c410624/java/com/google/copybara/config/SkylarkParser.java and then https://github.com/google/copybara/blob/d4f9bd37ddf6eb51f1072ffb4e61332f7c410624/java/com/google/copybara/Core.java for even better inspiration.