Cross-build to sbt 2 and Scala 3.#674
Conversation
Two sbt 2 incompatibilities fixed: - paradoxDirectives += CustomDirective fails on sbt 2 because the task result type (functions) has no JsonFormat, which sbt 2 requires for disk caching. Changed to := Def.uncached(Writer.defaultDirectives :+ CustomDirective) to bypass the cache entirely. - In sbt 2, Compile/target resolves to target/out/jvm/scala-<ver>/<name> instead of target/. The paradox output was landing in the wrong directory. Changed defineSiteMappings to anchor the output at baseDirectory.value / "target" so the path stays stable across sbt versions. Also wrapped SbtWeb.syncMappings in Def.uncached so sbt 2 does not skip the file sync when restoring from task cache.
Fixes:
- docs-overlay: Rename configs to docsFirst/docsSecond, add docsOverlayParadox task
- generated-source: Replace in syntax with / in PageGenerator.scala
- libraryDependencies: Use builtinParadoxTheme("generic")
- snippet-noindent-writer, snippets: Regenerate expected HTML for Scala 3
- validation: Add sbt2-compat, use PluginCompat.toFileRefsMapping
- custom-directive: Use := Def.uncached(...) for paradoxDirectives; add sbt2-compat
- ParadoxPlugin: Use baseDirectory/target for output; wrap syncMappings in Def.uncached
Tradeoffs:
- docs-overlay: Hyphenated config invocation no longer tested; workaround via camelCase + wrapper task
- libraryDependencies: Material theme no longer exercised; only generic theme verified
- snippets: Expected HTML now Scala 3 format; Scala 2 brace-style output no longer covered
- validation: Test depends on sbt2-compat; no longer a minimal vanilla setup
- custom-directive: paradoxDirectives += no longer used; breaking change for users on sbt 2
…ot ported to sbt 2 yet
johanandren
left a comment
There was a problem hiding this comment.
I'm not deeploy familiar with all the required changes for sbt-2, but I think this looks good.
|
@johanandren thank you for taking a look! I've fixed the formatting with a |
|
Thanks @anatoliykmetyuk! I can review at sbt 2.x specific parts, but at a glance, the lion's share of the changes seems to be to bring up old code base into Scala 3.x, which includes using 2.13 stdlib. |
| (paradoxTheme / WebKeys.deduplicators).value, | ||
| fileConverter.value | ||
| ), | ||
| paradoxTheme / target := baseDirectory.value / "target" / "paradox" / "theme" / configTarget(configuration.value), |
There was a problem hiding this comment.
Could we use
target.value / "paradox" / "theme" / configTarget(configuration.value),like it was before, so it's safe against cross building?
There was a problem hiding this comment.
The paths seem to differ between sbt 1 and 2 which causes inconsistent behavior. I've mentioned this one at the PR changes above:
On sbt 2, target.value inside inConfig(Compile) resolves to a versioned subdirectory (
target/out/jvm/scala-3.8.1/<project>/) instead oftarget/as on sbt 1. This makes the output path of the plugin inconsistent. Changed paths to preserve the sbt 1 behavior throughout ParadoxPlugin.scala.
The current setup should produce consistent paths during cross-build.
eed3si9n
left a comment
There was a problem hiding this comment.
I have a minor question about target directory, but overall lgtm
e3befcb to
a11bfe8
Compare
|
The formatting failure seems to be due to the new |
This PR cross-compiles the plugin to Scala 3 and sbt 2, making it possible to use from sbt 2 projects. It's a big PR, so here's a summary of all the changes by category to assist with reviewing. Virtually all the changes introduced by the PR are covered by one of the categories below.
CI/Testing
Test / parallelExecution := falsein core and tests to fix.verifyinstead oftest:githubWorkflowBuildinbuild.sbtnow invokesverify(Test/compile, Compile/doc, test, scripted, docs/paradox), so scripted tests run in CI. Also CI is running sbt with--batchflag to prevent interactive prompts on project loading failures which are not suitable for automated scripts.Scala 3 Compatibility
compat/package.scalathat maps to JavaConverters (2.12) or CollectionConverters (2.13/3) so core cross-compiles.java.util.List.asScala(JavaConverters) returnsscala.collection.mutable.Buffer, which extendsscala.collection.Seq. In Scala 3:java.util.Collection.asScala(CollectionConverters) returnsscala.collection.Iterable, which does not extendscala.collection.Seq. Therefore we standardize by adding.toSeqwhere APIs are expectingSeq[String].com.lightbend.paradox.markdown.Urlhad a customcopy(path, query, fragment)method that conflicted with the case class's syntheticcopyin Scala 3; renamed towithComponentsso core cross-compiles.MarkdownTestkit: disambiguatedPathname collision betweenjava.nio.file.Pathandcom.lightbend.paradox.markdown.Path. Scala 2 and 3 use different resolution strategies so a collision happens in Scala 3. The port added explicitjava.nio.file.PathandParadoxPathalias to avoid relying on context-dependent resolution.LinkDirectiveSpec) that useimplicit val contextfor the writer context now have an explicit type:Location[Page] => Writer.Context.sbt 2 Compatibility
Def.uncached.insyntax (e.g.key in scope) with sbt 2 slash syntax (scope / key).sbt-webfrom1.5.8to1.6.0-M2to support sbt 2; the new API requiresfileConverter.valueforsyncMappingsanddeduplicateMappings, due to changes in file types between sbt 1 and sbt 2.ScmInfo.browseUrlfromjava.net.URLtojava.net.URI- standardize onjava.net.URI.ParadoxPlugin.scala: inlinedsourcesForat its single call site in. Originally it was in the compat layer for sbt 0.13 support, but the plugin no longer cross-builds to sbt 0.13.target.valueinsideinConfig(Compile)resolves to a versioned subdirectory (target/out/jvm/scala-3.8.1/<project>/) instead oftarget/as on sbt 1. This makes the output path of the plugin inconsistent. Changed paths to preserve the sbt 1 behavior throughoutParadoxPlugin.scala.Scripted Tests
paradox/docs-overlayscripted test was updated to use camelCase configs (docsFirst,docsSecond).paradox/snippet-noindent-writerandparadox/snippetsexpected HTML updated to match current source files. Scripted tests were not tested by the CI so the html files for those tests were broken by an scalafmt run a while ago.paradox/libraryDependenciestest was filtered for sbt 2 as the material plugin is not yet ported to sbt 2. Exclusion logic inbuild.sbt:verify-no-dockersbt command was changed from a simple alias to a command to enable filtering logic. scripted tests plugin checks for sbt version in build.properties to determine if it matches the sbt version the test is tested against - however this feature does not work in case of glob references, e.g.paradox/*. Logic inverifycommand works properly because no globs are used.