Over a million developers have joined DZone.

Creating a javadoc Rule for Bazel

How to generate javadocs with Bazel with a new downloadable plugin and a few lines of code.

· DevOps Zone

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

A couple of users have asked about how to generate javadoc with Bazel. There’s no built-in way, but I figured it might be useful to whip together a new rule to do so.

Here it is.

If you’d like to use this rule, download it to your workspace, load it in your build file, and give it a list of sources:

load("/javadoc", "javadoc")
 
javadoc(
    name = "app-doc",
    srcs = glob(["**/*.java"]),
)

Then build:

$ bazel build :app-doc
INFO: Found 1 target...
Target //:app-doc up-to-date:
  bazel-bin/app-doc.zip
INFO: Elapsed time: 0.141s, Critical Path: 0.00s

Now, if you look at bazel-bin/app-doc.zip, you can see that it contains the HTML tree generated by javadoc:

$ unzip -l bazel-bin/app-doc.zip
Archive:  bazel-bin/app-doc.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     6990  2015-09-28 15:06   app-doc/SomeClass.html
      568  2015-09-28 15:06   app-doc/allclasses-frame.html
      548  2015-09-28 15:06   app-doc/allclasses-noframe.html
...

You can then unzip it wherever you want to view your docs.

Note that this is an extremely limited implementation: I just dashed this off in 20 minutes. It doesn’t support any javadoc options and probably doesn’t handle dependencies correctly. Let me know if you have any issues with it and I can implement improvements as needed.

This entry was posted Monday, September 28th, 2015 at 12:24 pm and is filed under Bazel. You can skip to the end and leave a response. Pinging is currently not allowed.

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

Topics:
bazel ,build ,devops ,open source ,java ,javadoc

Published at DZone with permission of Kristina Chodorow, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}