Skip to content

Commit 955fca7

Browse files
authored
Fix doc generation for projects with compile-only dependencies (#3990)
1 parent 8a66208 commit 955fca7

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ object Build {
5555
isPartial: Boolean,
5656
logger: Logger
5757
) extends Build {
58-
def success: Boolean = true
59-
def cancelled: Boolean = false
60-
def successfulOpt: Some[this.type] = Some(this)
61-
def outputOpt: Some[os.Path] = Some(output)
62-
def dependencyClassPath: Seq[os.Path] = sources.resourceDirs ++ artifacts.classPath
63-
def fullClassPath: Seq[os.Path] = Seq(output) ++ dependencyClassPath
58+
def success: Boolean = true
59+
def cancelled: Boolean = false
60+
def successfulOpt: Some[this.type] = Some(this)
61+
def outputOpt: Some[os.Path] = Some(output)
62+
def dependencyClassPath: Seq[os.Path] = sources.resourceDirs ++ artifacts.classPath
63+
def dependencyCompileClassPath: Seq[os.Path] =
64+
sources.resourceDirs ++ artifacts.compileClassPath
65+
def fullClassPath: Seq[os.Path] = Seq(output) ++ dependencyClassPath
66+
def fullCompileClassPath: Seq[os.Path] = fullClassPath ++ dependencyCompileClassPath
6467
private lazy val mainClassesFoundInProject: Seq[String] = MainClass.find(output, logger).sorted
6568
private lazy val mainClassesFoundOnExtraClasspath: Seq[String] =
6669
options.classPathOptions.extraClassPath.flatMap(MainClass.find(_, logger)).sorted

modules/cli/src/main/scala/scala/cli/commands/doc/Doc.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scala.cli.commands.doc
22

33
import caseapp.*
44
import caseapp.core.help.HelpFormat
5+
import coursier.Fetch
56
import dependency.*
67

78
import java.io.File
@@ -147,7 +148,7 @@ object Doc extends ScalaCommand[DocOptions] {
147148
builds.find(_.scope == Scope.Test).getOrElse(builds.head).project.scaladocDir
148149
case Some((_, true)) => builds.head.project.scaladocDir
149150
case Some((scalaParams, _)) =>
150-
val res = value {
151+
val res: Fetch.Result = value {
151152
Artifacts.fetchAnyDependencies(
152153
Seq(Positioned.none(dep"org.scala-lang::scaladoc:${scalaParams.scalaVersion}")),
153154
value(builds.head.options.finalRepositories),
@@ -162,7 +163,11 @@ object Doc extends ScalaCommand[DocOptions] {
162163
val ext = if Properties.isWin then ".exe" else ""
163164
val baseArgs = Seq(
164165
"-classpath",
165-
builds.flatMap(_.fullClassPath).distinct.map(_.toString).mkString(File.pathSeparator),
166+
builds
167+
.flatMap(_.fullCompileClassPath)
168+
.distinct
169+
.map(_.toString)
170+
.mkString(File.pathSeparator),
166171
"-d",
167172
destDir.toString
168173
)

modules/integration/src/test/scala/scala/cli/integration/DocTestDefinitions.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,21 @@ abstract class DocTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
8080
}
8181
}
8282
}
83+
84+
if actualScalaVersion.startsWith("3") then
85+
test("doc with compileOnly.dep") {
86+
TestInputs(
87+
os.rel / "project.scala" ->
88+
s"""//> using compileOnly.dep org.springframework.boot:spring-boot:3.5.6
89+
|//> using test.dep org.springframework.boot:spring-boot:3.5.6
90+
|""".stripMargin,
91+
os.rel / "RootLoggerConfigurer.scala" ->
92+
s"""import org.springframework.beans.factory.annotation.Autowired
93+
|import scala.compiletime.uninitialized
94+
|
95+
|class RootLoggerConfigurer:
96+
| @Autowired var sentryClient: String = uninitialized
97+
|""".stripMargin
98+
).fromRoot(root => os.proc(TestUtil.cli, "doc", ".", extraOptions).call(cwd = root))
99+
}
83100
}

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,40 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
348348
expect(r.out.trim() == expectedMessage)
349349
}
350350
}
351+
352+
if actualScalaVersion.startsWith("3") then
353+
test("publish local with compileOnly.dep") {
354+
TestInputs(
355+
os.rel / "project.scala" ->
356+
s"""//> using compileOnly.dep org.springframework.boot:spring-boot:3.5.6
357+
|//> using test.dep org.springframework.boot:spring-boot:3.5.6
358+
|
359+
|//> using publish.organization my.org
360+
|//> using publish.name scala-cli-publish-bug
361+
|//> using publish.version 1.0.0
362+
|""".stripMargin,
363+
os.rel / "RootLoggerConfigurer.scala" ->
364+
s"""import org.springframework.beans.factory.annotation.Autowired
365+
|import scala.compiletime.uninitialized
366+
|
367+
|class RootLoggerConfigurer:
368+
| @Autowired var sentryClient: String = uninitialized
369+
|""".stripMargin
370+
).fromRoot { root =>
371+
val scalaVersionArgs =
372+
if (actualScalaVersion == Constants.scala3Next)
373+
Seq("-S", actualScalaVersion)
374+
else Nil
375+
os.proc(
376+
TestUtil.cli,
377+
"--power",
378+
"publish",
379+
"local",
380+
".",
381+
scalaVersionArgs,
382+
extraOptions
383+
)
384+
.call(cwd = root)
385+
}
386+
}
351387
}

0 commit comments

Comments
 (0)