Skip to content

Commit 17f87be

Browse files
committed
Move Develocity config to CustomDevelocityPlugin
1 parent 16d70cb commit 17f87be

File tree

3 files changed

+82
-67
lines changed

3 files changed

+82
-67
lines changed

project/Build.scala

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import sbt.nio.Keys.*
1111
import complete.DefaultParsers._
1212
import pl.project13.scala.sbt.JmhPlugin
1313
import pl.project13.scala.sbt.JmhPlugin.JmhKeys.Jmh
14-
import com.gradle.develocity.agent.sbt.DevelocityPlugin.autoImport._
15-
import com.gradle.develocity.agent.sbt.api.experimental.buildcache
14+
import sbt.CustomDevelocityPlugin.autoImport._
1615
import com.typesafe.sbt.packager.Keys._
1716
import com.typesafe.sbt.packager.MappingsHelper.directory
1817
import com.typesafe.sbt.packager.universal.UniversalPlugin
@@ -281,8 +280,6 @@ object Build {
281280

282281
val fetchScalaJSSource = taskKey[File]("Fetch the sources of Scala.js")
283282

284-
val extraDevelocityCacheInputFiles = taskKey[Seq[Path]]("Extra input files for caching")
285-
286283
lazy val SourceDeps = config("sourcedeps")
287284

288285
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
@@ -318,56 +315,6 @@ object Build {
318315

319316
// enable verbose exception messages for JUnit
320317
(Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"),
321-
322-
// Configuration to publish build scans to develocity.scala-lang.org
323-
develocityConfiguration := {
324-
val isInsideCI = insideCI.value
325-
val config = develocityConfiguration.value
326-
val buildScan = config.buildScan
327-
val buildCache = config.buildCache
328-
// disable test retry on compilation test classes
329-
val noRetryTestClasses = Set(
330-
"dotty.tools.dotc.BestEffortOptionsTests",
331-
"dotty.tools.dotc.CompilationTests",
332-
"dotty.tools.dotc.FromTastyTests",
333-
"dotty.tools.dotc.IdempotencyTests",
334-
"dotty.tools.dotc.ScalaJSCompilationTests",
335-
"dotty.tools.dotc.TastyBootstrapTests",
336-
"dotty.tools.dotc.coverage.CoverageTests",
337-
"dotty.tools.dotc.transform.PatmatExhaustivityTest",
338-
"dotty.tools.repl.ScriptedTests"
339-
)
340-
config
341-
.withProjectId(ProjectId("scala3"))
342-
.withServer(config.server.withUrl(Some(url("https://develocity.scala-lang.org"))))
343-
.withBuildScan(
344-
buildScan
345-
.withPublishing(Publishing.onlyIf(_.authenticated))
346-
.withBackgroundUpload(!isInsideCI)
347-
.withTag(if (isInsideCI) "CI" else "Local")
348-
.withLinks(buildScan.links ++ GithubEnv.develocityLinks)
349-
.withValues(buildScan.values ++ GithubEnv.develocityValues)
350-
.withObfuscation(buildScan.obfuscation.withIpAddresses(_.map(_ => "0.0.0.0")))
351-
)
352-
.withBuildCache(
353-
buildCache
354-
.withLocal(buildCache.local.withEnabled(true).withStoreEnabled(true))
355-
.withRemote(buildCache.remote.withEnabled(true).withStoreEnabled(isInsideCI))
356-
.withRequireClean(!isInsideCI)
357-
)
358-
.withTestRetry(
359-
config.testRetry
360-
.withFlakyTestPolicy(FlakyTestPolicy.Fail)
361-
.withMaxRetries(if (isInsideCI) 1 else 0)
362-
.withMaxFailures(10)
363-
.withClassesFilter((className, _) => !noRetryTestClasses.contains(className))
364-
)
365-
},
366-
// Deactivate Develocity's test caching because it caches all tests or nothing.
367-
// Also at the moment, it does not take compilation files as inputs.
368-
Test / develocityBuildCacheClient := None,
369-
extraDevelocityCacheInputFiles := Seq.empty,
370-
extraDevelocityCacheInputFiles / outputFileStamper := FileStamper.Hash,
371318
)
372319

373320
// Settings shared globally (scoped in Global). Used in build.sbt
@@ -449,16 +396,6 @@ object Build {
449396
Package.ManifestAttributes(
450397
"Automatic-Module-Name" -> s"${dottyOrganization.replaceAll("-",".")}.${moduleName.value.replaceAll("-",".")}"
451398
),
452-
453-
// add extraDevelocityCacheInputFiles in cache key components
454-
Compile / compile / buildcache.develocityTaskCacheKeyComponents +=
455-
(Compile / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
456-
Test / test / buildcache.develocityTaskCacheKeyComponents +=
457-
(Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
458-
Test / testOnly / buildcache.develocityInputTaskCacheKeyComponents +=
459-
(Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
460-
Test / testQuick / buildcache.develocityInputTaskCacheKeyComponents +=
461-
(Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue
462399
)
463400

464401
// Settings used for projects compiled only with Java

project/CustomDevelocityPlugin.scala

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package sbt
2+
3+
import sbt.Keys.*
4+
import sbt.nio.Keys.*
5+
import sbt.nio.FileStamper
6+
import com.gradle.develocity.agent.sbt.DevelocityPlugin
7+
import com.gradle.develocity.agent.sbt.DevelocityPlugin.autoImport.*
8+
import com.gradle.develocity.agent.sbt.api.experimental.buildcache
9+
import java.nio.file.Path
10+
11+
object CustomDevelocityPlugin extends AutoPlugin {
12+
override def requires: Plugins = DevelocityPlugin
13+
14+
override def trigger: PluginTrigger = allRequirements
15+
16+
object autoImport {
17+
val extraDevelocityCacheInputFiles = taskKey[Seq[Path]]("Extra input files for caching")
18+
}
19+
import autoImport.*
20+
21+
override def buildSettings: Seq[Def.Setting[?]] = Seq(
22+
develocityConfiguration := {
23+
val isInsideCI = insideCI.value
24+
val config = develocityConfiguration.value
25+
val buildScan = config.buildScan
26+
val buildCache = config.buildCache
27+
// disable test retry on compilation test classes
28+
val noRetryTestClasses = Set(
29+
"dotty.tools.dotc.BestEffortOptionsTests",
30+
"dotty.tools.dotc.CompilationTests",
31+
"dotty.tools.dotc.FromTastyTests",
32+
"dotty.tools.dotc.IdempotencyTests",
33+
"dotty.tools.dotc.ScalaJSCompilationTests",
34+
"dotty.tools.dotc.TastyBootstrapTests",
35+
"dotty.tools.dotc.coverage.CoverageTests",
36+
"dotty.tools.dotc.transform.PatmatExhaustivityTest",
37+
"dotty.tools.repl.ScriptedTests"
38+
)
39+
config
40+
.withProjectId(ProjectId("scala3"))
41+
.withServer(config.server.withUrl(Some(url("https://develocity.scala-lang.org"))))
42+
.withBuildScan(
43+
buildScan
44+
.withPublishing(Publishing.onlyIf(_.authenticated))
45+
.withBackgroundUpload(!isInsideCI)
46+
.withTag(if (isInsideCI) "CI" else "Local")
47+
.withLinks(buildScan.links ++ GithubEnv.develocityLinks)
48+
.withValues(buildScan.values ++ GithubEnv.develocityValues)
49+
.withObfuscation(buildScan.obfuscation.withIpAddresses(_.map(_ => "0.0.0.0")))
50+
)
51+
.withBuildCache(
52+
buildCache
53+
.withLocal(buildCache.local.withEnabled(true).withStoreEnabled(true))
54+
.withRemote(buildCache.remote.withEnabled(true).withStoreEnabled(isInsideCI))
55+
.withRequireClean(!isInsideCI)
56+
)
57+
.withTestRetry(
58+
config.testRetry
59+
.withFlakyTestPolicy(FlakyTestPolicy.Fail)
60+
.withMaxRetries(if (isInsideCI) 1 else 0)
61+
.withMaxFailures(10)
62+
.withClassesFilter((className, _) => !noRetryTestClasses.contains(className))
63+
)
64+
},
65+
// Deactivate Develocity's test caching because it caches all tests or nothing.
66+
// Also at the moment, it does not take compilation files as inputs.
67+
Test / develocityBuildCacheClient := None,
68+
extraDevelocityCacheInputFiles := Seq.empty,
69+
extraDevelocityCacheInputFiles / outputFileStamper := FileStamper.Hash,
70+
)
71+
72+
override def projectSettings: Seq[Def.Setting[?]] = Def.settings(
73+
// add extraDevelocityCacheInputFiles in cache key components
74+
Compile / compile / buildcache.develocityTaskCacheKeyComponents += (Compile / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
75+
Test / test / buildcache.develocityTaskCacheKeyComponents += (Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
76+
Test / testOnly / buildcache.develocityInputTaskCacheKeyComponents += (Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue,
77+
Test / testQuick / buildcache.develocityInputTaskCacheKeyComponents += (Test / extraDevelocityCacheInputFiles / outputFileStamps).taskValue
78+
)
79+
}

project/GithubEnv.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import scala.util.Properties
2-
import sbt.url
3-
import java.net.URL
1+
package sbt
42

3+
import scala.util.Properties
54

65
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#default-environment-variables
76
object GithubEnv {

0 commit comments

Comments
 (0)