我使用Gradle(v2.3)进行项目,其中包含多个Scala子项目。为每个子项目单独生成ScalaDoc可以按预期工作(运行gradle :project-a:scaladoc
或gradle :project-b:scaladoc
)。
但是如何获得所有 Scala子项目的单个 ScalaDoc?下面的最小项目会导致& #34;无法在null对象上调用withInputStream()方法" 错误,执行时
gradle scaladoc --info
:
Starting Build
Compiling settings file '/tmp/gradle-scaladoc-test/settings.gradle' using StatementExtractingScriptTransformer.
Compiling settings file '/tmp/gradle-scaladoc-test/settings.gradle' using BuildScriptTransformer.
Settings evaluated using settings file '/tmp/gradle-scaladoc-test/settings.gradle'.
Projects loaded. Root project using build file '/tmp/gradle-scaladoc-test/build.gradle'.
Included projects: [root project 'some project', project ':project-a', project ':project-b']
Evaluating root project 'some project' using build file '/tmp/gradle-scaladoc-test/build.gradle'.
Compiling build file '/tmp/gradle-scaladoc-test/build.gradle' using StatementExtractingScriptTransformer.
Compiling build file '/tmp/gradle-scaladoc-test/build.gradle' using BuildScriptTransformer.
Evaluating project ':project-a' using empty build file.
Evaluating project ':project-b' using empty build file.
All projects evaluated.
Selected primary task 'scaladoc' from project :
Tasks to be executed: [task ':scaladoc', task ':project-a:compileJava', task ':project-a:compileScala', task ':project-a:processResources', task ':project-a:classes', task ':project-a:scaladoc', task ':project-b:compileJava', task ':project-b:compileScala', task ':project-b:processResources', task ':project-b:classes', task ':project-b:scaladoc']
:scaladoc (Thread[main,5,main]) started.
:scaladoc
Executing task ':scaladoc' (up-to-date check took 0.448 secs) due to:
No history is available.
:scaladoc FAILED
:scaladoc (Thread[main,5,main]) completed. Took 0.768 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':scaladoc'.
> Cannot invoke method withInputStream() on null object
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 5.198 secs
Stopped 0 compiler daemon(s).
目录结构:
├─ project-a/
│ └─ src/
│ └─ main/
│ └─ scala/
│ └─ package_a/
│ └─ A.scala
├─ project-b/
│ └─ src/
│ └─ main/
│ └─ scala/
│ └─ package_b/
│ └─ B.scala
├─ build.gradle
└─ settings.gradle
的build.gradle
subprojects {
repositories {
mavenCentral()
}
apply plugin: 'scala'
dependencies {
compile 'org.scala-lang:scala-library:2.11.6'
}
tasks.withType(ScalaCompile) {
scalaCompileOptions.additionalParameters = ['-unchecked', '-deprecation', '-feature']
scalaCompileOptions.useAnt = false
}
}
task scaladoc(type: org.gradle.api.tasks.scala.ScalaDoc) {
group = 'Documentation'
description = 'Aggregated ScalaDoc documentation.'
title = 'Title of documentation'
destinationDir = new File(buildDir, "aggregated-api")
source subprojects.collect { project ->
project.sourceSets.main.allScala
}
scalaClasspath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
}
settings.gradle
rootProject.name = 'some project'
include 'project-a', 'project-b'
A.scala
package package_a
case class A(value: Int)
B.scala
package package_b
case class B(value: Int)
我能找到的唯一类似问题是"Gradle Fails to Compile Basic Scala Project",但它在这里没有帮助(并且是关于Gradle 1.3)。
答案 0 :(得分:1)
我知道已经有一段时间了,因为有人问过这个问题,但是因为我遇到了同样的问题......
我通过以下方式解决了这个问题:
task aggregatedScaladocs(type: ScalaDoc, description: 'Generate scaladocs from all child projects as if it were a single project', group: 'Documentation') {
destinationDir = file("$buildDir/docs/scaladoc")
title = "$project.name $version API"
subprojects.each { proj ->
proj.tasks.withType(ScalaDoc).each {
source += proj.sourceSets.main.allJava
source += proj.sourceSets.main.allScala
classpath += proj.sourceSets.main.compileClasspath
excludes += scaladoc.excludes
includes += scaladoc.includes
}
}
}
希望它能在某些时候帮助某人。
答案 1 :(得分:0)
对于 6.x版,我需要使用@juwi稍作修改的答案。
task aggregatedScaladocs(type: ScalaDoc, description: 'Generate scaladocs from all child projects as if it were a single project', group: 'Documentation') {
destinationDir = file("$buildDir/docs/scaladoc")
title = "$project.name $version API"
classpath = project.files([])
scalaClasspath = project.files([])
subprojects.each { proj ->
proj.tasks.withType(ScalaDoc).each {
source proj.sourceSets.main.allJava
source proj.sourceSets.main.allScala
classpath += proj.scaladoc.classpath
scalaClasspath += proj.scaladoc.scalaClasspath
exclude proj.scaladoc.excludes
include proj.scaladoc.includes
}
}
}