【问题标题】:What to include in build.gradle for Scala/Gradle在 Scala/Gradle 的 build.gradle 中包含什么
【发布时间】:2014-01-26 15:45:17
【问题描述】:

我想将 Gradle 用于多模块 Scala 项目。我不知道如何将 genjavadoc-plugin 用于 Scala 编译器。理想情况下,我想为我的每个库生成.jar-sources.jar-javadocs.jar.jar-sources.jar 很简单,但 javadocs 有点难。在 Maven 和 SBT 中,您可以使用 genjavadoc-plugin 从 Scala 生成支持 JavaDoc 的代码,然后运行 ​​JavaDoc。我不得不认为这在 Gradle 中同样可能,只是我对 Gradle / Groovy 的了解还不够。

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

build.gradle 中应该包含什么来支持这一点?

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

【问题讨论】:

    标签: java scala documentation gradle build-process


    【解决方案1】:

    嗯,这个是我自己想出来的。我在这里发布它,希望其他人会发现它有用。我没有发布我的整个 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")
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2022-01-15
      • 2017-01-31
      • 2010-10-15
      相关资源
      最近更新 更多