Get classpath for gradle project using Android plugin

后端 未结 4 722
旧巷少年郎
旧巷少年郎 2021-01-13 08:55

I\'ve been building some tasks for a gradle multi-project build and have a need to get the class path for a project. The build script has projects that use the Java plugin

4条回答
  •  忘掉有多难
    2021-01-13 09:37

    Here is another example a gradle task that generates javadocs with umlgraph + graphiz in an android project and includes classpath for all variants using the coding example given in the user1737310's previous answer. It is manually including android.jar from the selected runtime, I am still looking for a way to retrieve it dynamically.

        task javadoc(dependsOn: build) {
        setDescription('Generates Javadoc API documentation with UMLGraph diagrams')
        setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
    
        doLast {
            def javaFilePath = file('src/main/java')
            def cp = [System.getenv('ANDROID_HOME')+'/platforms/android-26/android.jar'];
            project.android.applicationVariants.all { v ->
                v.getCompileClasspath(null).getFiles().each{
                    File f->
                        cp.add(f.getAbsolutePath())//this is the one of classpath
                }
            }
            def classpath = ":"+cp.join(':')
            if (javaFilePath.exists()) {
                ant.javadoc(classpath: (configurations.umljavadoc).asPath + classpath, 
                            sourcepath: file('src/main/java'), 
                            packagenames: '*',
                            destdir: "${docsDir}/javadoc",
                            private: 'false',
                            docletpath: configurations.umljavadoc.asPath) {
                    doclet(name: 'org.umlgraph.doclet.UmlGraphDoc') {
                        param(name: '-inferrel')
                        param(name: '-inferdep')
                        param(name: '-qualify')
                        param(name: '-postfixpackage')
                        param(name: '-hide', value: 'java.*')
                        param(name: '-collpackages', value: 'java.util.*')
                        param(name: '-nodefontsize', value: '9')
                        param(name: '-nodefontpackagesize', value: '7')
                        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')
                    }
                }
            }
        }
    }
    

    `

提交回复
热议问题