Using scala with new java-library api/implementation

Hi, I have a Java library that was using java-library plugin for api/implementation declarations, and now I’m trying to add an internal dependency on a scala project. So usually I would apply the scala plugin instead of java, but in this case it’s a java-library. Is that support or a roadmap for scala libraries? Or perhaps a different approach to deal with a java library that has project dependency on a scala project? Thanks.

It doesn’t matter what plugin the producer project is using, java-library will still work.

I’m trying to add an internal dependency on a scala project. So usually I would apply the scala plugin instead of java, but in this case it’s a java-library.

I think there’s a misunderstanding here. You don’t need to add the scala plugin in order to depend on a scala project. Projects interact through artifacts and every JVM language produces classes in the end, so they are all compatible.

Finally, the java-library plugin can also be used together with the scala plugin on the same project, which basically makes it a Scala library. This doesn’t quite work out of the box yet, see the limitations section in the user guide. We’ll fix that soon.

Thank you Stefan. Configuring scala with java-library using the link you sent fixed it.

Regarding your statement:

You don’t need to add the scala plugin in order to depend on a scala project. Projects interact through artifacts and every JVM language produces classes in the end, so they are all compatible.

I thought I at least understood that for external projects where you’re depending on an already-built artifact (say, in Maven repo). But in this case, the java and scala projects are in a single multi-project build. If I just apply the java-library plugin to my java project (not scala), then in that java project if I instantiate a scala case class (whose source is in the scala project), I get a compile error that the symbol can not be found. I thought maybe it has to do with the compileJava task not invoking compileScala on the project containing its scala dependency. Is that correct? How would you recommend configuring a java project that depends on a scala project in the same build?

Thanks again!

No, projects don’t “invoke” things in other projects. Projects interoperate through artifacts and each project knows how to build its artifacts. So the error you described must have been due to some other misconfiguration. A reproducible example project would help find out what the problem is.

There is nothing special to do there, it’s a dependency like any other.