How do I make a Javadoc task use my compile's dependencies?


(Robert Rapplean) #1

I’ve inserted a Javadoc task into my Java compile, but it’s erroring out telling me it can’t find any of the classes that I included in the dependencies. The code builds and tests without a problem, it just won’t generate Javadocs. Here’s a snippet of the build:

task generateJavaDocs(type: Javadoc, dependsOn: 'compileJava') {
  source = sourceSets.main.allJava
  title = "My API"
  options.setHeader "MyBuildStuff"
}
  task docJar(type: Jar, dependsOn: 'generateJavaDocs') {
  classifier = 'javadoc'
 from('build/docs')
}
dependencies {
 compile "org.springframework:spring-beans:$spring_version"
}

And an example error:

C:\Users\me\workspace\project\src\main\java\com\us\project\classname.java:15: error: package org.springframework.beans.factory.config does not exist
import org.springframework.beans.factory.config.ConfigurableBeanFactory;

Can anyone tell me what I’m doing wrong?


(Peter Niederwieser) #2

You can just use the ‘javadoc’ task added by the ‘java’ plugin.


(Robert Rapplean) #3

Peter, I think that’s what I did, isn’t it? I found an example in the documentation that uses it through inheritance, so I pretty much cut and paste from that.


(Peter Niederwieser) #4

No, that’s not what you are doing. You are declaring your own ‘Javadoc’ task named ‘generateJavaDocs’, rather than using the preconfigured ‘Javadoc’ task named ‘javadoc’.