Commit ff6c502
Cross-build for sbt 1.x and sbt 2.x (#209)
* Cross-build for sbt 1.x and sbt 2.x
sbt 2.0.0 introduces several breaking API changes for plugins (built with
Scala 3): apiMappings is now Map[HashedVirtualFileRef, URI] instead of
Map[File, URL], the dependency classpath holds Attributed[HashedVirtualFileRef],
the ModuleID is stored as a JSON string under a StringAttributeKey, inTask was
removed, and task results are cached by default.
This change makes the plugin cross-build for both sbt 1.x (Scala 2.12) and
sbt 2.x (Scala 3):
- build.sbt: crossScalaVersions = [2.12.20, 3.8.4] with pluginCrossBuild /
sbtVersion selecting sbt 1.12.11 / 2.0.0 per Scala binary version.
- Most of the sbt 2.x divergence is absorbed by sbt2-compat (PluginCompat:
FileRef, moduleIDStr, parseModuleIDStrAttribute, Def.uncached), keeping the
rule sources shared.
- A small version-specific Compat object (src/main/scala-2.12, src/main/scala-3)
holds only what sbt2-compat cannot unify: the api doc URL type (URL vs URI),
the synthetic bootstrap classpath key (which cannot go through fileConverter),
and the `.extract` adapter (an implicit Extractor on Scala 2.12; a
PartialFunction-returning extension on Scala 3, where a PartialFunction is
already a valid pattern).
- breakOut / inTask removed in favour of cross-version-friendly equivalents.
- CI matrix and scripted test assertions updated for both sbt versions.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Scope all task-body reads to config / doc after dropping inConfig/inTask
Replacing `inConfig(config) { inTask(doc) { ... } }` with explicit
`config / doc / key` settings also changed the scope in which the `.value`
reads inside the task bodies resolve. Only `apiMappings` and
`dependencyClasspath` had been re-scoped; `apiMappingRules`,
`bootstrapJavadocURL` and `streams` were left unscoped and resolved in the
default/global scope instead of `config / doc`, so a user override such as
`Compile / doc / apiMappingRules += ...` would no longer be picked up.
Re-scope every read in both task bodies to `config / doc`, matching the
original inConfig/inTask behavior.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Reuse the extractor library via a private Compat.Extractor
Make `.extract` opt-in and keep it out of `com.thoughtworks`:
- `Compat` is now `private[sbtApiMappings]` and exposes a nested `Extractor`
member, imported with `import Compat.Extractor._`. This avoids leaking the
`.extract` implicit onto every function via `import Compat._`.
- On Scala 2.12, `Compat.Extractor` is `val Extractor = com.thoughtworks.Extractor`,
i.e. a re-export of the `com.thoughtworks.extractor` library (added back as a
Scala-2.12-only dependency). The library is reused as-is; its `sealed`
`private[thoughtworks]` traits cannot be wrapped, but a plain `val` alias
re-exports the object so its implicits come in through `import Compat.Extractor._`.
- On Scala 3 `Compat.Extractor` is an `object` whose `extension` turns a
function/partial function into a `PartialFunction` (already a valid pattern on
Scala 3). No `com.thoughtworks.Extractor` shim, so the package is not polluted.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Fix scripted test fixtures for sbt 2.x
CI on sbt 2.0.0 surfaced two sbt-1-isms in the test fixtures (keep-api-url
already passed; only all-libraries and jdk failed):
- all-libraries/test used the sbt 0.13 colon command syntax
`+compile:doc::apiMappings`, which sbt 2.x rejects ("Expected ';'"). Switch to
slash syntax `+Compile / doc / apiMappings`.
- jdk/build.sbt read `sLog.value` in its check/fgrep/jgrep tasks. On sbt 2.x a
Logger has no `HashWriter`, so reading it as a task input breaks the default
task caching ("given evidence sjsonnew.HashWriter[...Logger...] is not found").
Use `println` for the diagnostic output instead — no task input needed. (The
`Map[HashedVirtualFileRef, URI]` from apiMappings does have a HashWriter, as
the passing keep-api-url test shows, so only the Logger was the problem.)
Both changes are also valid on sbt 1.x.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Run only keep-api-url scripted test under sbt 2.x
The all-libraries and jdk scripted fixtures use very old Scala versions
(2.12.10 / 2.13.1 / 2.13.8) whose sbt 2.x Zinc compiler bridges fail to build,
and they assert sbt 1.x-specific behaviour (the scaladoc `target/api` output
path and the autoAPIMappings scala-library URL), which differs on sbt 2.x.
Until those fixtures are modernised, gate them to sbt 1.x: under sbt 2.x run
only keep-api-url (which exercises the full rule pipeline end-to-end), while
sbt 1.x keeps running all three. The sbt 2.x code path is also covered by
`+compile` / `+Test/compile`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Make all-libraries and jdk scripted tests pass on both sbt versions
Modernise the two fixtures so they run under both sbt 1.x and sbt 2.x, and
remove the temporary sbt-2.x gating:
- Bump their Scala versions (2.12.10 / 2.13.1 / 2.13.8 -> 2.12.20 / 2.13.16) so
the sbt 2.x Zinc compiler bridge builds, and scalacheck to 1.18.1.
- all-libraries: the scala-library and scalacheck api doc URLs differ by sbt
version (autoAPIMappings reads the POM `apiURL` on sbt 1.x — e.g.
https://www.scala-lang.org/api/<v>/ and https://www.javadoc.io/doc/<...> — while
on sbt 2.x this plugin's own rules provide http://scala-lang.org/files/archive/
api/<v>/ and https://javadoc.io/page/<...>). Assert leniently (host + version)
so one test covers both.
- jdk: the scaladoc output directory is `target/api` on sbt 1.x but
`target/out/jvm/<...>/api` on sbt 2.x, so the hard-coded `$ exists` / `jgrep`
path no longer works. Move the file checks into a `checkDoc` task that locates
the directory via `Compile / doc / target`.
Verified locally (JDK 17): `++2.12.20 test` and `++3.8.4 test` both run all three
scripted tests plus the unit test green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Rename Compat to Compatibility
Use the full word `Compatibility` instead of the abbreviation `Compat` for the
plugin's internal version-specific object. (sbt2-compat's `PluginCompat` /
`sbtcompat` are unchanged.)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Rename Compatibility.DocUrl to Compatibility.URL
`URL` reads better than `DocUrl` for the api-doc value type of the `apiMappings`
map. The alias resolves to `java.net.URL` on sbt 1.x and `java.net.URI` on
sbt 2.x.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 2342070 commit ff6c502
19 files changed
Lines changed: 303 additions & 170 deletions
File tree
- .github/workflows
- .vscode
- src
- main
- scala-2.12/com/thoughtworks/sbtApiMappings
- scala-3/com/thoughtworks/sbtApiMappings
- scala/com/thoughtworks/sbtApiMappings
- sbt-test/sbt-api-mappings
- all-libraries
- jdk
- keep-api-url
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | | - | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
35 | | - | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
54 | | - | |
| 61 | + | |
55 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
18 | 46 | | |
19 | 47 | | |
20 | 48 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
Lines changed: 18 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
Lines changed: 21 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
| 69 | + | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
Lines changed: 17 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | | - | |
28 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
Lines changed: 11 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | | - | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
| |||
0 commit comments