要在Scala/Gradle的build.gradle中包含什么

fbl*_*fbl 4 java documentation build-process scala gradle

我想将Gradle用于多模块Scala项目.我无法弄清楚如何为Scala编译器使用genjavadoc-plugin.理想情况下,我想为每个库生成一个.jar,-sources.jar-javadocs.jar.在.jar-sources.jar很简单,但是是的Javadoc有点困难.在Maven和SBT中,您可以使用genjavadoc-plugin从Scala生成JavaDoc-able代码,然后运行JavaDoc.我不得不认为它在Gradle中同样可行,我只是不知道Gradle/Groovy能够做到这一点.

我可以制作ScalaDocs,但这些库是由Java开发人员使用的,他们希望将JavaDocs附加到.jarsEclipse中,我认为这是一个非常合理的请求.

应该包括哪些build.gradle来支持这个?

编译器插件在这里:https: //github.com/typesafehub/genjavadoc

fbl*_*fbl 6

好吧,我自己想出了这个.我在这里发帖,希望别人会发现它有用.我不发布我的整个build.gradle文件,只发布配置scala项目的部分(我也有一些纯java项目).基本上,您将genjavadoc-plugin添加到依赖项中,传递一些参数,并确保将"genjavadoc"目录添加到javadoc任务中.

// specific config for scala projects
configure(scalaProjects) {
    apply plugin: 'scala'

    // this little hack zeroes out the java source directories
    // so that the scala plugin can handle them
    sourceSets.main.scala.srcDir "src/main/java"
    sourceSets.main.java.srcDirs = []
    sourceSets.test.scala.srcDir "src/test/java"
    sourceSets.test.java.srcDirs = []


    // define a configuration for scala compiler plugins
    // the transitive=false means that the plugin won't show up
    // as a dependency in the final output
    configurations {
        scalaCompilerPlugins { transitive = false }
    }

    // this plugin will transform .scala files into javadoc'able .java files
    // so that the regular javadoc will run
    dependencies {
        scalaCompilerPlugins  group: 'com.typesafe.genjavadoc', name: 'genjavadoc-plugin_2.10.2', version:'0.5'
        compile group: 'org.scala-lang', name: 'scala-library', version:'2.10.2'
        compile group: 'org.scala-lang', name: 'scala-compiler', version:'2.10.2'
    }

    // this string contains theplugin paths that get passed to the compiler
    def pluginPaths = configurations.scalaCompilerPlugins.files.collect { "\"-Xplugin:${it.path}\"" }

    // this is the genjavadoc arguments - effectively it tells the plugin where to put the generated code
    compileScala.scalaCompileOptions.additionalParameters = pluginPaths + "\"-P:genjavadoc:out=$buildDir/genjavadoc\""

    task javaDocs(type : Javadoc) {
        source = fileTree("src/main/java").include("*.java") + fileTree("$buildDir/genjavadoc")
        options.addStringOption("-quiet")
    }

}
Run Code Online (Sandbox Code Playgroud)