Include local javadoc with gradle

Hi there,
I am trying to figure out a way to show javadoc from a local .jar in my project, so I can see the documentation in intelliJ (and possible also NetBeans).

My build.gradle contains the following to include the local jars:

dependencies {
    compile fileTree(dir: "./src/libs/", includes: ['*.jar'])

and in the libs folder is three .jar files (compiled java, sources and javadoc) all for the same project.

What I cannot figure out it how get intelliJ to read the javadoc and show that. I made a small task with

task listJars {
    configurations.compile.each { File file -> println }

to confirm that all the .jar files are included, which they are. The task outputs:


The -javadoc.jar was created in another project with the javadoc task.

I also have

apply plugin: 'idea'
idea {
    module {
        downloadJavadoc = true

which is not really helping me in this case

Hope you guys can help!

The simplest way to achieve this is layout the jars in a maven style directory layout.



You can then reference the dependency in your build

repositories {
   maven {
      url file('mavenRepo') 
dependencies {
   compile 'group:PickRandomStudent:1.0'

This has the added benefit that the jars can now properly participate in Gradle’s dependency resolution process

1 Like

Ah yes! Thank you very much @Lance !

In IntelliJ 2018.3.3 with Gradle 5.1 this seems to be broken. I still have the three files locally and the jar file with the classes are correctly recognized and can be imported and used. The source and javadoc however are not.

In the ./idea/libraries folder that is created by IntelliJ i can find the file:
Gradle__dk_kaspersoerensen_PickRandomStudent_1_0.xml that looks like this:

<component name="libraryTable">
  <library name="Gradle: dk.kaspersoerensen:PickRandomStudent:1.0">
      <root url="jar://$PROJECT_DIR$/lib/dk/kaspersoerensen/PickRandomStudent/1.0/PickRandomStudent-1.0.jar!/" />
    <JAVADOC />
    <SOURCES />

Clearly both <JAVADOC> and <SOURCES> are empty. Filling them out manually with the path to the -javadoc.jar and -sources.jar resolves the problem, but I am wondering if the idea plugin to Gradle should do this, when calling the idea task?

If I use external packages from the MavenCentral there is no problem downloading the sources and javadoc. These will both be listed in the ./idea/libraries folder.

When using the ideaModule task, the .iml file does look correct, but the javadocs are still not available.

<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <orderEntry type="inheritedJdk"/>
    <content url="file://$MODULE_DIR$/">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false"/>
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true"/>
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource"/>
      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource"/>
      <excludeFolder url="file://$MODULE_DIR$/.gradle"/>
      <excludeFolder url="file://$MODULE_DIR$/build"/>
    <orderEntry type="sourceFolder" forTests="false"/>
    <orderEntry type="module-library">
          <root url="jar://$MODULE_DIR$/externalJars/dk/kaspersoerensen/PickRandomStudent/1.0/PickRandomStudent-1.0.jar!/"/>
          <root url="jar://$MODULE_DIR$/externalJars/dk/kaspersoerensen/PickRandomStudent/1.0/PickRandomStudent-1.0-javadoc.jar!/"/>
          <root url="jar://$MODULE_DIR$/externalJars/dk/kaspersoerensen/PickRandomStudent/1.0/PickRandomStudent-1.0-sources.jar!/"/>
  <component name="ModuleRootManager"/>

this burn me some hours: if you have an “aar”:

compile ‘group:PickRandomStudent:1.0@aar’

Since version 6.0, it’s necessary for the repositories block to look something like this:

repositories {
    maven {
        url file('mavenRepo) 
        metadataSources {

See here.