sbt / sbt

sbt, the interactive build tool
https://scala-sbt.org
Apache License 2.0
4.79k stars 935 forks source link

/lib jars still found even if unmanagedBase is changed #1335

Closed francisdb closed 10 years ago

francisdb commented 10 years ago

I'm trying to migrate a legacy java project to sbt. Therefore I want to gradually replace the provided jars in lib to managed ones

as I want to ignore the lib folder in my build.sbt I have this:

unmanagedBase := baseDirectory.value / "donotuse"

compile correctly causes my build to fail because of missing dependencies.

Then I add one of the lib jars to the build

unmanagedJars in Compile += file("lib/mylib.jar")

compile succeeds, suddenly all other jars in lib are also added to the java compiler. I would expect them to still be ignored and only mylib.jar to be available.

Am I doing this the wrong way or is this a bug? The intelliJ sbt plugin seems to correctly only add the mylib.jar to my project. Any workaround for this issue would be welcome.

some more debug (jdk 8)

> show sbtVersion
[info] 0.13.2
> show unmanagedBase
[info] /Users/xxx/Documents/workspace/MyProject/donotuse
> show unmanagedClasspath
[info] List(Attributed(lib/mylib.jar))
> show unmanagedJars
[info] ArrayBuffer(Attributed(lib/mylib.jar))

I do however see these logs

[debug] External API changes: API Changes: Set()
[debug] Modified binary dependencies: Set(/Users/xxx/Documents/workspace/MyProject/lib/ST-4.0.7.jar, /Users/xxx/Documents/workspace/MyProject/lib/commons-logging-1.0.4.jar, /Users/xxx/Documents/workspace/MyProject/lib/twitter4j-stream-3.0.4.jar, /Users/xxx/Documents/workspace/MyProject/lib/mail-1.4.7.jar, /Users/xxx/Documents/workspace/MyProject/lib/exp4j-0.3.10.jar, /Users/xxx/Documents/workspace/MyProject/lib/jsoup-1.7.3.jar, /Users/xxx/Documents/workspace/MyProject/lib/json-simple-1.1.1.jar, /Users/xxx/Documents/workspace/MyProject/lib/twitter4j-core-3.0.4.jar, /Users/xxx/Documents/workspace/MyProject/lib/jspf.core-1.0.2.jar)
cunei commented 10 years ago

I cannot replicate this behavior. I tried a setup similar to the one you describe, placing two jars in lib/, including only one of them via unmanagedJars, and redirecting unmanagedBase to a dummy directory. The library included via unmanagedJars is visible, the other is not found. I tested sbt 0.13.2. Can you please package a self-contained test case?

francisdb commented 10 years ago

Thanks @cunei for checking, just found the issue, seems that one of the jars I include has a manifest with a "Class-Path" property that points to the libs

Any idea on how I could ignore/modify that manifest using sbt? For reference: http://stackoverflow.com/questions/3800462/can-i-prevent-javac-accessing-the-class-path-from-the-manifests-of-our-third-par

jsuereth commented 10 years ago

Wow, Class-Path in a lib dependency feels evil....

And right now we don't really have a hook to rewrite jar files on the fly, but you could write such a task by hooking the dependencyClasspath task and altering the jars there.

francisdb commented 10 years ago

@jsuereth evil indeed, thanks for the hint