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

Packages including "scala-library" in its name cannot be imported by other projects. #7511

Open
ddl-sacuna opened this issue Mar 12, 2024 · 1 comment
Labels

Comments

@ddl-sacuna
Copy link

ddl-sacuna commented Mar 12, 2024

steps

Trying to create a package with a name including the string scala-library in it, results in a failure when trying to use that package from another project.

Details

A "library" project defined as

// build.sbt
import sbt.file

lazy val root =
  Project(id = "my-scala-library", base = file("."))
    .settings(
      name := "my-scala-library-that-fails",
      scalaVersion := "2.13.12",
      organization := "com.myorg",
    )

with just one file

//  src/main/scala/com/myorg/Lib.scala
package com.myorg

object Lib {
  def MyFunc() = 1
}

and a project trying to use it

//  build.sbt
import sbt.file

lazy val foo =
  Project(id = "foo", base = file("."))
    .settings(
      name := "foo",
      organization := "com.myorg",
      scalaVersion := "2.13.12",
      libraryDependencies ++= Seq(
        "com.myorg" %% "my-scala-library-that-fails" % "0.1.0-SNAPSHOT",
      ),
      resolvers += Resolver.mavenLocal
    )
// src/main/scala/foo/Foo.scala
package foo

import com.myorg.Lib

object Foo {
  def main(args: Array[String]) = {
    println(Lib.MyFunc())
  }
}

And running

sbt publishM2

on the library, and

sbt compile

on the consumer results in a failure

repro.tar.gz

problem

❯ sbt compile
[info] welcome to sbt 1.9.9 (Homebrew Java 21.0.2)
[info] loading project definition from .../consumer/project
[info] loading settings for project foo from build.sbt ...
[info] set current project to foo (in build file:.../consumer/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to .../consumer/target/scala-2.13/classes ...
[error] .../consumer/src/main/scala/foo/Foo.scala:3:12: object myorg is not a member of package com
[error] import com.myorg.Lib
[error]            ^
[error] .../consumer/src/main/scala/foo/Foo.scala:7:13: not found: value Lib
[error]     println(Lib.MyFunc())
[error]             ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

expectation

I'm able to import symbols from the package

notes

I tried looking if this behavior is intended, and could not find anything.
If the package name for the library is something else like my-scala-lib-that-fails, then it works without a problem.

@ddl-sacuna ddl-sacuna added the Bug label Mar 12, 2024
@eed3si9n
Copy link
Member

eed3si9n commented Apr 4, 2024

@ddl-sacuna Thanks for the report! I think this is a bug, but it might be tricky to fix if it's somewhere deeply rooted in layered classloader logic or something because at that point all we got would be JAR names.

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

No branches or pull requests

2 participants