[scala] Add cross compilation for scala 2.12 and 2.13#2547
Conversation
Generated by 🚫 Danger |
|
Thanks for your PR! Currently (before this PR), PMD builds against org.scalameta:scalameta_2.13 which in turn is built against scala 2.13. Due to incompatibilities between scala 2.12 and scala 2.13, one cannot use pmd-scala in a scala 2.12 project - one would need to update to scala 2.13. According to the travis builds of sbt-cpd, it uses scala 2.10 and scala 2.12. One incompatibility is the It seems, we updated the scala version with PMD 6.18.0, so pmd-scala <= 6.17.0 supports scala 2.12 and pmd-scala >= 6.18.0 requires scala 2.13 So, would if be enough maybe, if we fix the When adding cross-compiled modules, I wonder, how many versions of scala we need to support? Is scala 2.12 and 2.13 enough or do we also need to support 2.11 and 2.10 and later 2.14. (2.14 probably won't come, see Scala 2 Roadmap Update. So, the number of modules would be limited - which is a relief. Adding support for cross-compiled modules in the way you did, has some problems:
So, if we need to support such "real" cross-compiled builds, I'd rather look into a solution, that integrates this via additional maven modules (like it is done here: https://github.com/random-maven/scalor-maven-plugin/tree/master/src/it/test-cross). The sources are shared via sym-link but each modules builds against a specific scala version. Using this project layout, a single maven build is enough to produce all artifacts. Next steps:
|
Correct, I would just add that
Yes this makes the the pmd-scala java code source-compatible with scala 2.12 and 2.13, but does not make it binary compatible between scala 2.12 and 2.13 (because we have a dependency on scalameta we have a dependency also on the scala std library which is not binary compatible...)
I would say this will not work, but OTOH this seems to work for the current version of sbt-cpd. The current version of
The consensus in the scala comunity is to support the current scala version (2.13) and the previous one (2.12). However we also need to consider that pmd will mostly be used from an sbt plugin and sbt plugins must target scala 2.12. So maybe would be enough to just support scala 2.12? However that would be a breaking change since pmd-scala already targets 2.13...
I would really not do this, since it does not follow the scala conventions...
I completely understand your points, and I will try what you propose with
|
Yes, I feared that - it might be accidentally compatible, but it is not guaranteed to work (the similar case is happening with java's bootclasspath...).
Thanks for clarifying which versions should be supported - it seems, the PMD then should also support both version 2.12 and 2.13.
Ok, so I'd suggest the following modules:
That's a good question. It can only depend on one version. pmd-dist is used to create the CLI version of PMD and is pretty self-contained. I guess, we can leave it at 2.13 then? I was googling yesterday a bit about the symlink solution: while this is a no-brainer for linux/macosx, I'm not sure, whether PMD would still be able to be built under Windows. Maybe an alternative to the symlink solution could be, to override the default sourceDirectoy, e.g. That is a bit unusual (maybe the IDEs are confused then)... something to test :) The directory structure I propose looks like this: The modules list in the main parent pom of PMD: I've not tried it out, whether that would work.... |
|
Hi @adangel I tried to do the structure you proposed without symlinks trick, but even after reconfiguring all the sourceDirectories and resourceDirectories, the tests were failing with: So I gave up and used symlinks instead and things seem to work... |
* Avoid using symlinks, this is very difficult to get working under Windows * Provide names for the different scala modules * Rename pmd-scala to pmd-scala-common * Restore main module pmd-scala for backwards compatibility
|
@jtjeferreira Thanks for the update. I'm working on it now and do the following changes:
|
Due to the different project structure, the paths need to be adjusted
This is due to changed project structure in pmd-scala
| - secure: "VezxV+VdmbmtrQYT8AZIyg41WBROxuxpumerkcubADF7V4wV6lwx9Rd2G6yAr0VuHCNUUhS4m+gPFIsuiQbAhyupiEkwhzUYqk1tF+LITlLLPegLypjiLmhJMwGUNuDSSsih1Icmg9FzrP4VyzgGn9pBjoG9QYj1civBZeGwg++e/XDYlHMXrpd/UEfMKVB71JwB0tle4fKJZSvblIqP62yvbBaKHx6A4+ZWzJV5Vps0DoIeNtKCNmNNloKZVHfjbsvqSjnMYUJzkOzyPkM822q41N/D+3IAufO16+jH/W0vAZeN0e4GXiN5W+CVkr2Gbh0FwkVQcI3bekaOIn45XLUMLKdf+JsWDPKz9RraHelR9YxL5GoJ7ntwvmucxw0p8EVyJ/xLk/pBCP8iHq0Jb8//js25XHgxzzAWI37MErPAAGgTKZAVdAN0mGXbe63tWmwaBlEbK8h2A8di6abW5x6YHTkTo2BRlHUSTU8dE3VqTnpSkne5n1SlEa4g1Bci3J45M0/pLmHV6yCxCM5BrVXS5ByaB61py/umSbpmdIBFV6TM1MaKK3lAucQrR+8To/vCbm8XqPyujJdOR+ENIuuDgEU/Yh5Hv5SAODekUYaCp4pjfGzFADHQWVNDxIOXrwBN4OfSiAvRc1x6HXndOmNI4QtOxheuCRFFthq8VZI=" | ||
| - GITHUB_BASE_URL=https://api.github.com/repos/pmd/pmd | ||
| git: | ||
| symlinks: true |
There was a problem hiding this comment.
should this be reverted?
There was a problem hiding this comment.
Good point. I think, yes, we should revert this, because this will give us an early indication (via the travis build for windows) when we use symlinks, which is not user friendly on windows unfortunately.
I'll revert this change when merging...
[scala] Add cross compilation for scala 2.12 and 2.13 #2547
Describe the PR
Introduces scala cross compilation so that this pmd can be used in https://github.com/sbt/sbt-cpd
I have looked into davidB/scala-maven-plugin#177 and this seems to be the best way to add cross compilation to a maven module.
There was only a change to actual code, since the method
iteratoronscala.collection.Iteratordoes not exist in scala 2.12. However it was not necessary to call it since we already have anIteratorI have also changed the travis scripts to build.
Ready?
./mvnw clean verifypasses (checked automatically by travis)