From d7a4cf59543aefc2dd81cd5d64ac445a7133fbaf Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Wed, 25 Jan 2023 22:13:07 -0800 Subject: [PATCH] Enable -source-links for Scala 3 --- .../GithubActionsScaladocSourceUrl.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala b/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala index 521c338..782bb40 100644 --- a/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala +++ b/github-actions/src/main/scala/com/thoughtworks/sbtBestPractice/githubActions/GithubActionsScaladocSourceUrl.scala @@ -33,6 +33,25 @@ object GithubActionsScaladocSourceUrl extends AutoPlugin { originalScalacOptions } }, + Compile / doc / scalacOptions ++= { + if (scalaBinaryVersion.value == "3") { + for { + repositoryBuilder <- GitPlugin.gitRepositoryBuilder.?.value + workTree <- GitPlugin.gitWorkTree.value + slug <- GithubActionsEnvironmentVariables.githubRepository.?.value + } yield { + val repository = repositoryBuilder.build() + try { + val hash = repository.resolve(Constants.HEAD).name + raw"-source-links:$workTree=github://$slug/$hash" + } finally { + repository.close() + } + } + } else { + None + } + }, scalacOptions in Compile in doc := { val originalScalacOptions = (scalacOptions in Compile in doc).value (GitPlugin.gitRepositoryBuilder.?.value, GithubActionsEnvironmentVariables.githubRepository.?.value) match {