Generating Javadoc in a JAR


I've got a module (MyModule) and want to produce 2 jars:

1. MyModule.jar - containing the executables for a library
2. MyModule-javadocs.jar -  containing the javadoc for the library

How do I do this?

The nearest I've got is creating an artifact for both jars above and for (2) having an ant target "doc" which is run from the "pre-processing" action - this runs javadoc on my module and writes the output to a directory (javadoc_out). The main part of artifact (2) just includes this javadoc_out directory.

This does not work the first time I build - I only get jar (1). The second time I build, both jars (1) and (2) are produced. So it never works from a clean build.

I can't figure out why. I think it may be something to do with artifact (2) not having the javadoc output directory existing until the pre-process step is run or something.
Any ideas?


Comment actions Permalink

Keep in mine that IntelliJ IDEA is an IDE and not a build tool. While it can do some basic build tasks including creating a JAR, once you get beyond the basis, you need to move to a build tool.

Creating a separate bin and javadoc jars is a piece of cake for Maven. It's built right in. While I have not used Gradle, I know it similarly can do such a thing. And Ant can do this as well, although yo need to write the script to do it.

My suggestion it so use a build tool to do this rather than trying to hack something in IDEA.

In regards to the issue you are having in that you need to run it twice... my suspicion is that however the javadocs are being created, it is requiring the built classes (or something else that happens in the build process.). So when you run the javadoc as a pre-complie task for a clean build, it cannot create anything.

Comment actions Permalink

Thanks for the reply. I'll probably change the build to ANT at some point.

For now, if I can resolve the "building twice" issue I'll be happy.
From teamcity, I give the 2 artifact names to build. If I do the same from the IDE "All Artifacts > Build" I get the same behaviour.

The javadoc output directory is created the first time, it is just never zipped up into the MyModule-javadocs.jar (i.e. the artifact is never produced first time).
The javadoc artifact contains the javadoc output directory and nothing else. Is the artifact not being built because it doesn't exist until after the pre-processing step is done?



Please sign in to leave a comment.