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

semanticDbData target fails for mixed scala/java modules #2981

Open
patrick-schultz opened this issue Jan 19, 2024 · 3 comments
Open

semanticDbData target fails for mixed scala/java modules #2981

patrick-schultz opened this issue Jan 19, 2024 · 3 comments

Comments

@patrick-schultz
Copy link

For example:

// build.sc
import mill._
import mill.scalalib._
object foo extends ScalaModule {
  def scalaVersion = "2.12.15"
}

// foo/src/Foo.scala
package foo
object Foo {
  val value = "hello"
}

// foo/src/Bar.java
package foo;
public class JFoo {
    String value = foo.Foo.value();
}

With this, mill foo.compile works fine, but mill foo.semanticDbData fails with

[42/42] foo.semanticDbData
[info] compiling 1 Scala source and 1 Java source to /Users/pschulz/dev/mill-playground/out/foo/semanticDbData.dest/classes ...
[error] /Users/pschulz/dev/mill-playground/foo/src/JFoo.java:7:1: cannot find symbol
[error]   symbol:   class Foo
[error]   location: package foo
[error] foo.Foo
1 targets failed
foo.semanticDbData javac returned non-zero exit code
@patrick-schultz patrick-schultz changed the title semanticDbData target fails for mixed scala/java modules semanticDbData target fails for mixed scala/java modules Jan 19, 2024
@patrick-schultz patrick-schultz changed the title semanticDbData target fails for mixed scala/java modules semanticDbData target fails for mixed scala/java modules Jan 19, 2024
@patrick-schultz patrick-schultz changed the title semanticDbData target fails for mixed scala/java modules semanticDbData target fails for mixed scala/java modules Jan 19, 2024
@lefou
Copy link
Member

lefou commented Jan 21, 2024

Thanks for reporting!

This issue is probably due to the fact, that the Scala compiler understands Java code but does not compile it, so we can have Scala code see Java code, but to have Java code see the Scala version, we need the compiled classfiles. The semanticDbData task is currently not generating class files, as a performance measure. Tests with pure Scala projects showed, it works this way. But we never analyzed this for mixed modules and need to retest this scenario.

We might want to try and reevaluate these options:

  • Detect a mixed setup, and don't stop compilation after semanticDb data generation phase

  • Let the semanticDbData task depend on compile, to have the readily compiled Scala code in the classpath. This means, we can only generate semanticDb data after the compilation was successful.

  • find other solutions...

@patrick-schultz
Copy link
Author

Thanks for the response! We were able to work around the issue by avoiding Java->Scala dependencies, so this is no longer critical for us.

@james-s-w-clark
Copy link
Contributor

james-s-w-clark commented Apr 16, 2024

I'm revisiting a mill 0.10.n -> 0.11.m upgrade and seeing this.

Regarding the second option, if I do:

mill mixedModule.compile
// [info] compiling 3 Scala sources and 1 Java source to .......

ls ./out/mixedModule/..../compile.dest/classes/....
// MyJavaFile.class, SomeScala.class

mill mixedModule.semanticDbData
// [info] compiling 3 Scala sources and 1 Java source to ....
...
// ...MyJavaFile.java error: cannot find symbol
//      SomeScala.doThing()......
//      ^ symbol ...        
// javac exited with exit code 1
// javac returned non-zero exit code

Does that invalidate it as a workaround in the meantime?

I might be misinterpreting, but before this 0.11 RC (https://github.com/com-lihaoyi/mill?tab=readme-ov-file#0110-m2---2023-01-13) java wasn't supported for semanticdb/scalafix right (makes sense, we didn't see this issue before)? I think we wouldn't mind just disabling it for Java files (to match old behaviour).

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

3 participants