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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 support #93

Open
akitaylor opened this issue Jan 2, 2024 · 8 comments · May be fixed by #97
Open

Scala 3 support #93

akitaylor opened this issue Jan 2, 2024 · 8 comments · May be fixed by #97

Comments

@akitaylor
Copy link

It would be great if the library could be used in Scala 3 projects. What are the prerequisites of this upgrade?
As I can see a new version of Shapeless library for Scala 3 exists, however I can't determine whether it is ready to be used in the current project: https://github.com/typelevel/shapeless-3

Is there any oher prerequisite of the migration?

Thanks!

@julienrf
Copy link
Owner

julienrf commented Jan 2, 2024

It is already possible to support Scala 3 by manually re-implementing the “automatic derivation” part with a macro. It might be possible to use Shapeless 3 to ease that work.

Unfortunately, note that Shapeless 3 is only available for Scala 3, which means that a solution that works for both Scala 2 and Scala 3 might be complicated to implement.

@henricook
Copy link

henricook commented Feb 15, 2024

Might you be able to help out those of us trying to migrate a little? It sounds like you've posted a solution here @julienrf but I don't know enough to fully understand it

The kind of Scala 3 compile issues I'm seeing currently are:

[error] 10 |  implicit val format: Format[ValidatedEntityDto] = flat.oformat((__ \ "type").format[String])
[error]    |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |missing argument for parameter derivedReads of method oformat in object flat: (implicit 
[error]    |  derivedReads:
[error]    |    shapeless.Lazy[
[error]    |      julienrf.json.derived.DerivedReads[
[error]    |        mydomain.account.dtos.ValidatedEntityDto,
[error]    |        julienrf.json.derived.TypeTag.ShortClassName]
[error]    |    ]
[error]    |  ,
[error]    |derivedOWrites:
[error]    |  shapeless.Lazy[
[error]    |    julienrf.json.derived.DerivedOWrites[
[error]    |      mydomain.account.dtos.ValidatedEntityDto,
[error]    |      julienrf.json.derived.TypeTag.ShortClassName]
[error]    |  ]
[error]    |): play.api.libs.json.OFormat[mydomain.account.dtos.ValidatedEntityDto]

@jvargas-lumu
Copy link

Question. If I am using play 3.0.5 with scala 3, there is no way yet to user your library?

@julienrf
Copy link
Owner

Hello, this is indeed not possible unless someone contributes Scala 3 support in play-json-derived-codecs instead of using Shapeless, or unless Shapeless 2 supports Scala 3.

@javierfvargas
Copy link

Hey Julien, same Javier from the previous question here, just from my personal account now. I have a working version in Scala 3. I'd like to share it with you. I modified your project to cross-compile. I can make a PR but it is not something you could merge because it is work in progress, new files are not documented, the SBT file should be reviewed, a some more details. Let me know what do you think would be the best course of action. I don't have any problem if you just copy the code, no credits are required from my side. I just want your library working again for us.

I already have it working great with a code I am migrating that used the Scala 2 version and didn't really need a lot of changes.

@javierfvargas
Copy link

@julienrf
Copy link
Owner

Hey Javier, thank you very much for sharing your work!
I had a cursory look and the changes look good. To move forward, I think it would be great if you could come up with a PR adding support for Scala 3 while still cross-compiling with Scala 2. Ideally, the test suite should also cross-compile and pass with both versions of the language. Is this something you would be interested in contributing?
I am happy to help or guide further, if needed!

@javierfvargas
Copy link

javierfvargas commented Nov 12, 2024

Julien. Actually, the project as I uploaded it is ready to be cross-compiled. Indeed, I did it locally using sbt +publishLocal and my project is using it as a dependency now. I followed https://docs.scala-lang.org/scala3/guides/migration/tutorial-macro-cross-building.html

Regarding unittests, What I did was to copy your tests to the scala-3 folder because I realized that some changes may be necessary. Also you can change across scala versions using ++3.3.3 and there you can run the tests, they run smoothly but when it tries to run the JS tests it fails in my environment because I think I do not have the JS artifacts to run them.

I could try to unify the unittests but if you could check the changes and let me know if you have any concerns it would be better.

I can trigger a PR so that you can leave comments and we move the conversation over the code there. I am willing to help but during work-days I will be slower.

@julienrf julienrf linked a pull request Nov 17, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

5 participants