scalacenter / scala3-migrate

A tool to help migrating from Scala 2 to Scala 3
https://docs.scala-lang.org/scala3/guides/migration/scala3-migrate.html
Apache License 2.0
110 stars 24 forks source link

_3 suffix added to pure Java projects #485

Closed DavidPerezIngeniero closed 3 months ago

DavidPerezIngeniero commented 3 months ago

I'd like to migrate a SBT project that has one Scala subproject that depends on several Java projects with no Scala.

For example oda is a Java subproject, and i see complains like:

error] Error downloading oda:oda_3:0.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /home/david/.ivy2/localoda/oda_3/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://ec.europa.eu/cefdigital/artifact/content/groups/public/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://nexus.osgeo.org/repository/Geoserver-releases/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://maven.geo-solutions.it/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://www.billylieurance.net/maven2/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   not found: https://jbig2-imageio.googlecode.com/svn/maven-repository/oda/oda_3/0.1.0-SNAPSHOT/oda_3-0.1.0-SNAPSHOT.pom
[error]   No fallback URL found

when running:

migrateTypes myScalaProject

Why ithe _3 suffix is added to a project that doesn't use Scala at all? Any workaround please?

Vinaypraba1998 commented 3 months ago

The issue you're encountering with the _3 suffix being appended to your Java subproject (e.g., oda) likely arises because SBT is trying to resolve dependencies for a Scala version that is not relevant to your Java subprojects.

Here are steps to resolve this:

  1. Define Java Subprojects Correctly: Make sure to define your Java subprojects without any Scala settings. You can do this by ensuring they do not have a Scala version defined and by specifying the projects as pure Java.

  2. Set Up Dependencies Properly: Ensure that your Scala subproject depends on the Java subprojects without appending the Scala version suffix.

Here is an example build.sbt that shows how to define and configure such a setup:

Root Project build.sbt

lazy val root = (project in file("."))
  .aggregate(myScalaProject, oda)
  .settings(
    name := "root",
    version := "0.1.0-SNAPSHOT"
  )

lazy val myScalaProject = (project in file("myScalaProject"))
  .settings(
    name := "myScalaProject",
    version := "0.1.0-SNAPSHOT",
    scalaVersion := "2.13.8",
    libraryDependencies ++= Seq(
      // Add your Scala dependencies here
    )
  )
  .dependsOn(oda)

lazy val oda = (project in file("oda"))
  .settings(
    name := "oda",
    version := "0.1.0-SNAPSHOT",
    crossPaths := false // This disables Scala version suffix
  )

Java Subproject oda/build.sbt

Since oda is a pure Java project, it should not require any special Scala configuration.

name := "oda"
version := "0.1.0-SNAPSHOT"
crossPaths := false

Scala Subproject myScalaProject/build.sbt

For the Scala subproject, make sure it properly depends on the Java subproject without adding a Scala version suffix.

name := "myScalaProject"
version := "0.1.0-SNAPSHOT"
scalaVersion := "2.13.8"

libraryDependencies ++= Seq(
  // Add your Scala dependencies here
)

dependsOn(oda)

Notes:

SBT Clean and Reload

After setting up your build.sbt files as above, run the following commands in your SBT shell to clean and reload the project:

sbt clean reload

By properly configuring the cross paths and dependencies, SBT should not append the _3 suffix to your Java projects, and the migration should proceed without errors related to Scala version suffixes.

adpi2 commented 3 months ago

As pointed out by @Vinaypraba1998 the workaround is to set crossPaths := false in your Java project.