Re: scalac compilation requires transitive dependencies on classpath at compile-time whereas javac does not
"P. Oscar Boykin" <[email protected]> Tue, 23 Feb 2016 15:47:10 -0800 (PST)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
I am working with bazel and scala: https://github.com/bazelbuild/rules_scala one thing bazel likes to do is separate compile and runtime dependencies. This is so we can better see if a target needs to be recompiled: if none of the compile time deps change their API, you don't need to recompile. Unfortunately, when trying to keep the deps tight we get a lot of warnings like: warning: Class org.apache.commons.logging.Log not found - continuing with a stub. My questions: 1) under what circumstances is this warning of an issue that will manifest as a failure at runtime *assuming at runtime that jar IS on the classpath*? 2) Is there a way to silence this warning safely without just addind more (unneeded, it seems) items to the classpath? 3) What could be done to better support build tools that try to keep compile dependencies as a subset of runtime dependencies that are actually needed by the source code in question? Thanks! On Thursday, December 5, 2013 at 10:13:43 AM UTC-10, Grzegorz Kossakowski wrote: > > On 5 December 2013 16:49, Chris Marshall <[email protected] <javascript:> > > wrote: > >> If I have a Java library *logging.jar *with a class in it like this >> >> class Log { >> public void log(String s) { System.out.println(s); } >> } >> >> >> >> If I then write a library *businessy.jar* which depends on logging.jar >> and which contains this class: >> >> abstract class Businessy { >> protected Log log = new Log(); >> public abstract void makeSomeMoney(); >> } >> >> >> Then, if I now write some Java code like so: >> >> class PetStore extends Businessy { >> public void makeSomeMoney() { /* sell pets */ } >> } >> >> >> Then *javac *will let me compile this code with *only* *businessy.jar* >> on my classpath [1]. However, if I write this scala code: >> >> class PetStore extends Businessy { >> def makeSomeMoney() { /* sell pets */ } >> } >> >> >> Then *scalac *will fail to compile it unless I *also* include >> *logging.jar*. That is, I have to know about the businessy library's >> transitive dependencies at compile time. I can't find any information about >> this requirement in the language spec, or any questions about it on the >> mailing lists (other than those assuming it as a *fait accompli*). So >> here are a few questions: >> >> >> 1. Why does scalac require these transitive deps to be present at >> compile time? >> >> Hi Chris, > > Not all transitive are necessarily required. However, in this case you are > inheriting from a class that has a protected field. It's visible to your > subclass so it's very likely that some piece of the code in scalac will try > to load it's type (e.g. override checks) even if it's not strictly > necessary. This behavior is not speced because it's an implementation > detail of the compiler. > > -- > Grzegorz Kossakowski > Scalac hacker at Typesafe <http://www.typesafe.com/> > twitter: @gkossakowski <http://twitter.com/gkossakowski> > github: @gkossakowski <http://github.com/gkossakowski> > > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.