Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package contains object and package with same name

I am having problems compiling some Scala with Maven or Eclipse where I try to import a class from a Java jar which contains both a namespace and class of the same name.
I can compile with scalac, however.

E.g. the Java project (jar) contains:

src/foo/bar.java

src/foo/bar/some_resource.txt

-> foobar.jar

Scala project references foobar.jar

Foobartest.scala:

import foo.bar

class foobartest {

}

The compiler complains with:

package foo contains object and package with same name: bar 
one of them needs to be removed from classpath

Using Maven 3.0.03/Eclipse 3.7.1 with Scala 2.9.0.1 (and maven-scala-plugin).

The jar which I am having problems with is jenkins-core-1.399.jar - it definitely contains several instances where there is a namespace and object of the same name.
I am attempting to write a Jenkins plugin in Scala (I could do this in Java but would prefer scala since all of our libraries are in scala), which is dependent on using Maven -
https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial.

like image 916
David Avatar asked Jan 24 '12 09:01

David


2 Answers

That kind of limitation was outlined in SI-4695: package object misbehaves in the presence of classfiles.

As suggested in SI-2089 (naming restriction makes some jars unusable), you could try and use the "resolve-term-conflict", as implemented in changeset 25145:

Added a -Y option to resolve namespace collisions between package and object.
It's a blunt instrument: if people have lots of these conflicts they need to resolve in individually nuanced fashion, they'll probably remain out of luck.

val termConflict  = ChoiceSetting     ("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", 113 List("package", "object", "error"), "error")

// Some jars (often, obfuscated ones) include a package and
// object with the same name. Rather than render them unusable,
// offer a setting to resolve the conflict one way or the other.
// This was motivated by the desire to use YourKit probes, which
// require `yjp.jar` at runtime. See SI-2089.
like image 131
VonC Avatar answered Nov 07 '22 23:11

VonC


The actual compiler option is "-Yresolve-term-conflict:strategy" where strategy is either package, object, error.

like image 20
liangzan Avatar answered Nov 07 '22 23:11

liangzan