Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use PureConfig in Scala 3? #1330

Closed
beneyal opened this issue Jun 19, 2022 · 11 comments
Closed

How to use PureConfig in Scala 3? #1330

beneyal opened this issue Jun 19, 2022 · 11 comments

Comments

@beneyal
Copy link

beneyal commented Jun 19, 2022

Hi 馃檪

I couldn't find an answer, so I hope it's okay I'm asking here.

I'm migrating a project to Scala 3.1.2, and have this line in my Dependencies.scala:

lazy val pureConfig: Seq[ModuleID] = Seq(
  "com.github.pureconfig" %% "pureconfig" % "0.17.1"
)

When I try to compile using SBT, I get an error Error downloading com.github.pureconfig:pureconfig_3:0.17.1 because it's not found.

My resolvers look like this:

resolvers ++= Seq(
  // a bunch of local resolvers
  Opts.resolver.mavenLocalFile,
  Resolver.defaultLocal,
  Resolver.mavenLocal,
  Resolver.sonatypeRepo("releases"),
  Resolver.sonatypeRepo("snapshots"),
  DefaultMavenRepository
)

What am I missing?

Thank you very much!

@bwbecker
Copy link

I'm attempting the same thing. I note that on Maven, pureconfig-core has an artifact for Scala3 (https://mvnrepository.com/artifact/com.github.pureconfig/pureconfig-core) but that just pureconfig does not (https://mvnrepository.com/artifact/com.github.pureconfig/pureconfig). pureconfig-generic also does not have a Scala3 artifact.

So my conclusion is that maintainers are in the process of converting the library but aren't done yet and we'll either need to get involved or be patient.

@leifwickland
Copy link
Collaborator

@ruippeixotog Does #1082 accurately describe what's holding up a Scala 3 version of pureconfig-generic?

@ruippeixotog
Copy link
Member

ruippeixotog commented Jun 28, 2022

Hey everyone! #1082 describes the shortcomings of our project structure, which isn't very user-friendly when it comes to Scala 3.

However, while #1082 makes things somewhat harder, I don't think it's the main reason why we don't have pureconfig-generic for Scala 3. Shapeless itself isn't published for Scala 3 and Scala 3's philosophy is a bit different when it comes to derived instances. There's https://github.com/typelevel/shapeless-3, but it's not a drop-in replacement for Scala 2 in any sense.

Scala 3 has built-in support for type class derivation, PureConfig has some early support for it, and I think that's the recommended way from now on - meaning that we'll probably never have some pureconfig-generic for Scala 3 and definitely never a drop-in replacement. We may have some optional pureconfig-shapeless3 or pureconfig-magnolia modules in the future that improve the capabilities of generic derivation or provide faster/better alternatives.

tl;dr: you'll have to start using pureconfig-core and migrate your code to use native Scala 3 derivation as described here.

@erikerlandson
Copy link
Contributor

I am starting to port coulomb-pureconfig into the Scala 3 world, and I'm trying to figure out what approaches are currently available to me.

My main interest is coming up with ConfigReader and ConfigWriter for the following sealed hierarchy RuntimeUnit:
https://github.com/erikerlandson/coulomb/blob/475db4ef4bb4ef2e19c8a9961f302f836cd9b455/runtime/src/main/scala/coulomb/runtime/runtime.scala#L24

IIUC, one can do derives ConfigReader, however I'd philosophically prefer to not bake pureconfig directly into coulomb-runtime. That leaves the following options:
https://pureconfig.github.io/docs/complex-types.html#complex-types

However Method-1 (again, IIUC) is not yet supported in scala-3 because it makes use of a CoproductHint.

So I wanted to ask, can I make use of Method 2 in scala 3 via pureconfig-core ?

(Method-3 makes use of shapeless, which I want to avoid since its relation to scala-3 is not yet very well defined)

@erikerlandson
Copy link
Contributor

@mdedetrich
Copy link
Contributor

mdedetrich commented Aug 20, 2023

Scala 3 has built-in support for type class derivation, PureConfig has some early support for it, and I think that's the recommended way from now on - meaning that we'll probably never have some pureconfig-generic for Scala 3 and definitely never a drop-in replacement. We may have some optional pureconfig-shapeless3 or pureconfig-magnolia modules in the future that improve the capabilities of generic derivation or provide faster/better alternatives.

tl;dr: you'll have to start using pureconfig-core and migrate your code to use native Scala 3 derivation as described here.

Is not having a pureconfig-generic a hard line in the sand? The reason why I am asking this is because it create a quite burden for libraries that depend on pureconfig to cross compile against Scala 2 vs Scala 3 due to differing source requirements.

This difference is also not trivial, it means that not only do you have to have separate variations ConfigReader (which byitelf would be annoying but at least more tolerable) but also the case class data structures that you are mapping your pureconfig readers to (Scala 2 doesn't have any support for generic derivation and hence code like sealed trait AnimalConf derives ConfigReader doesn't even compile for Scala 2).

If someone was to solve #1082 and also provide a pureconfig-generic for Scala 3 would it be considered for upstream?

@bambuchaAdm
Copy link

Do you think putting note about this in getting started would be helpful? I can create PR but need just acknowledge.

@ChidiRnweke
Copy link
Contributor

ChidiRnweke commented Mar 16, 2024

tl;dr: you'll have to start using pureconfig-core and migrate your code to use native Scala 3 derivation as described here.

Can this be added to the quick start of the documentation in the meantime? I think it would be helpful for Scala 3 users to figure this out without having to dig through issues to get it to work :)

If you give me the go I'm willing to draft a small PR to add ~5-10 lines to the docs (quickstart and readme.md) saying the users need to add "com.github.pureconfig" %% "pureconfig-core" % "0.17.6" in Scala 3 and refer them to the scala-3 derivation page.

@ruippeixotog
Copy link
Member

I'm happy to review PRs to improve documentation, @ChidiRnweke. Thanks for helping!

@ChidiRnweke
Copy link
Contributor

I'm happy to review PRs to improve documentation, @ChidiRnweke. Thanks for helping!

The (short documentation) PRs have been here for a while, can you merge it if you have the time? Thanks in advance :)

@ruippeixotog
Copy link
Member

Finally done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants