Enhance javadoc generation for specific Java project


(Paul Morrison) #1

I would like to enhance the javadoc task to generate additional javadoc entries based on annotations specific to my Java project. I have found a Java routine called Javadoc.java which looks interesting, but I thought tasks were written in C, and packaged as dlls. I am using Gradle-2.14.1.

My questions are: a) which module has to be modified to do this, and b) how do I get gradle build to pick up the modified module?


(Lance Java) #2

You can provide a custom doclet

configurations {
   mydoclet
}
dependencies {
   mydoclet project(':mydoclet')
}
javadoc {
   options.docletpath = configurations.mydoclet.files.asType(List)
   options.doclet = 'com.foo.MyDoclet'
}

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/doclet/overview.html


(Paul Morrison) #3

Many thanks, @Lance_Java, that looks pretty clear and complete! Wish me luck!

Regards,

Paul M.


(Paul Morrison) #4

Hi @Lance_Java (or anyone!), I have been struggling with this for a week now, and I apologize for being really dense. I think I need a Gradle for Dummies book!

I have stitched together a build.gradle from various sources (like StackOverflow), which I have used successfully to upload my project to Maven. I have a folder called mydoclet in my root folder (javafbp). When I tried adding the following, as per your suggestions, plus project, which is probably wrong :slight_smile: :

configurations {
   mydoclet
}
dependencies {
  mydoclet project(':mydoclet')
}

//task listComponentAttributes(type: Javadoc) {
javadoc {
  source = sourceSets.main.allJava
  destinationDir = reporting.file("build/docs/compattrs.txt")
  options.docletpath = configurations.mydoclet.files.asType(List)
  options.doclet = "ListClass "
}
   
project(':mydoclet') {
    task listComponentAttributes
}

I got this message:

> Could not get unknown property 'javadoc' for task ':mydoclet:javadocJar' of type org.gradle.api.tasks.bundling.Jar.

Some responses to queries seem to suggest I need a settings.gradle file - I created one saying include(':mydoclet')

Obviously I am missing some key concepts, but I find the Gradle documentation really confusing!

Here is my build.gradle - probably completely wrong! Also pls excuse lack of formatting! Help would be much appreciated! TIA

buildscript {  
repositories {
    mavenCentral()
}
dependencies {
    classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
 }
}
apply plugin: 'io.codearte.nexus-staging'


subprojects {
   

    task javadocJar(type: Jar) {
        classifier = 'javadoc'
        from javadoc
    }

    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    artifacts {
        archives javadocJar, sourcesJar
    }
    
    
}

allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'

apply plugin: 'maven'
apply plugin: 'signing'

version = '3.0.6'
group = 'com.jpaulmorrison'


description = 'Java Implementation of "Classical" Flow-Based Programming'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8



if (JavaVersion.current().isJava8Compatible()) {
//allprojects {
    tasks.withType(Javadoc) {
        options.addBooleanOption('Xdoclint:none', true)
    }
// }
 }

ext {
snapshotPublicationRepository = "https://oss.sonatype.org/content/repositories/snapshots/"
releasePublicationRepository = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"

// Credentials for publication repositories (needed only for publishing)
// Should be set in ${HOME}/.gradle/gradle.properties
ossrhUser =  project.hasProperty('ossrhUser') ? project.property('ossrhUser') : ""
osshrPassword = project.hasProperty('osshrPassword') ? project.property('osshrPassword') : ""
}

// Used to generate initial maven-dir layout
task "create-dirs" { description = "Create default maven directory structure" } << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}



jar {
manifest {
    attributes 'Implementation-Title': 'JavaFBP', 'Implementation-Version': version
}
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

 configurations {
 mydoclet
}
dependencies {
  mydoclet project(':mydoclet')
}

//task listComponentAttributes(type: Javadoc) {
javadoc {
  source = sourceSets.main.allJava
  destinationDir = reporting.file("build/docs/compattrs.txt")
  options.docletpath = configurations.mydoclet.files.asType(List)
  options.doclet = "ListClass "
}
   
project(':mydoclet') {
    task listComponentAttributes
}


signing {
sign configurations.archives
}

task writeNewPom << {
pom {
    project {
        groupId 'com.jpaulmorrison'
        artifactId 'javafbp'
        version '3.0.6'
    
        inceptionYear '2016'
        licenses {
            license {
                name 'GNU Lesser General Public License, Version 3.0'
                url 'https://www.gnu.org/licenses/lgpl-3.0.txt'
            }
        }

    }
    }.writeTo("pom.xml")
   }

uploadArchives {
 repositories {
 mavenDeployer {
  beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

  repository(url: releasePublicationRepository) {
    authentication(userName: ossrhUser, password: ossrhPassword)
  }

  snapshotRepository(url: snapshotPublicationRepository) {
   authentication(userName: ossrhUser, password: ossrhPassword)
  }

  pom.project {
    name 'JavaFBP'
    description 'Java Implementation of "Classical" Flow-Based Programming'
    groupId 'com.jpaulmorrison'
    packaging 'jar'
    // optionally artifactId can be defined here         
    url 'https://github.com/jpaulm/javafbp'
    version '3.0.6'

    scm {
      connection 'scm:git:https://github.com/jpaulm.git'
      developerConnection 'scm:git:https://github.com/jpaulm.git'
      url 'https://github.com/jpaulm.git'
     }

     licenses {
      license {
        name 'GNU Lesser General Public License, Version 3.0'
        url 'https://www.gnu.org/licenses/lgpl-3.0.txt'
      }
    }

    developers {
      developer {
        id 'jpaulmorr'
        name 'John Paul Rodker Morrison (Software architect)'
        email 'jpaulmorr@gmail.com'
      }
     }
     }
    }
  }
}
}
nexusStaging {  
  username = ossrhUser
 password = ossrhPassword
 }