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

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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")
    name = "app-doc",
    srcs = glob(["**/*.java"]),

Then build:

$ bazel build :app-doc
INFO: Found 1 target...
Target //:app-doc up-to-date:
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.

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

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.

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.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}