Tag Archives: Gradle

Javadoc with UML diagrams for Android project using (almost) only Gradle!

One of the important moments of documenting source code is creation UML diagrams. UML diagrams – a simple, unified and at the same time powerful means of description your of project from different sides.

Well, the project have written and commented in javadoc manner, how can you create and insert charts in documentation? You need a software, that makes reverse-engineering work for you. In Android case, actually, your choice is not so great: there are about five free solutions for convert your source code in javadoc with UML diagrams, but they are quite mighty.

In this post I show you how to use UMLGraph with Gradle to build docs from console.

  • first of all, you should download and install Graphviz. Graphviz is open source graph visualization software that process the output of UML doclet to png image diagram.
  • open build.gradle of your app module and add this code:
    allprojects {
    configurations {
        umljavadoc
    }

    dependencies {
        umljavadoc 'org.umlgraph:umlgraph:5.6'
    }

    //
    // While javadoc is not typically dependent on compilation, the compile steps
    // sometimes generate some sources that we wish to have in the Javadoc.
    //
    task javadoc(overwrite: true, dependsOn: build) {
        setDescription('Generates Javadoc API documentation with UMLGraph diagrams')
        setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)

        doLast {
            def javaFilePath = file('src/main/java')
            if (javaFilePath.exists())
            {
                ant.javadoc(classpath: "{path_to_android_sdk}/android.jar",
                        sourcepath: file('src/main/java'),
                        packagenames: '*',
                        destdir: "{path_to_project}/javadoc",
                        private: 'true',
                        docletpath: configurations.umljavadoc.asPath,
                        charset: 'UTF-8',
                        encoding: 'UTF-8',
                        docencoding: 'UTF-8') {
                    doclet(name: 'org.umlgraph.doclet.UmlGraphDoc')
                            {
                                param(name: '-nodefontsize', value: '9')
                                param(name: '-nodefontpackagesize', value: '7')
                                param(name: '-qualify')
                                param(name: '-postfixpackage')
                                param(name: '-hide', value: 'java.*')
                                param(name: '-collpackages', value: 'java.util.*')
                                param(name: '-inferrel')
                                param(name: '-inferdep')
                                param(name: '-link', value: 'http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/spec')
                                param(name: '-link', value: 'http://java.sun.com/j2se/1.5/docs/api')
                            }
                }
            }
            else
            {
                print("!!! Cannot find source path !!!");
            }
        }
    }
}
  • Specify your own classpath, destdir and other params you need.
  • open console and in project’s dir type gradlew javadoc.
  • That’s all! There is documentation with UML class diagrams in {path_to_project}/javadoc!