繁体   English   中英

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

[英]What to include in build.gradle for Scala/Gradle

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

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

build.gradle应包含build.gradle来支持此功能?

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

好吧,我自己想出了这个。 我在这里发帖,希望别人会发现它有用。 我不发布我的整个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")
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM