Java 8 is here.
Let's say that there is an old version of widget libray with the coordinates of Maven widgetmakers:widget:1.0.4 , which has a class defined in it as follows:
public class Widget { private String meow;
Years pass. The compilers of this widget library decide that a widget should never meow , but rather should be a bark . So, the new release is made with the coordinates of Maven widgetmakers:widget:2.0.0 and the widget looks like this:
public class Widget { private Bark bark;
So now I'm going to create my application, myapp . And, wanting to use the latest stable versions of all my dependencies, I declare my dependencies like this (inside build.gradle ):
dependencies { compile ( ,'org.slf4j:slf4j-api:1.7.20' ,'org.slf4j:slf4j-simple:1.7.20' ,'bupo:fizzbuzz:3.7.14' ,'commons-cli:commons-cli:1.2' ,'widgetmakers:widget:2.0.0' ) }
Now let's say that this (fictional) fizzbuzz always depended on version 1.x of the widget library, where the widget was meow .
So now I point out 2 versions of widget in my compilation paths class:
widgetmakers:widget:1.0.4 , which is inserted by the fizzbuzz library as a dependency on it; andwidgetmakers:widget:2.0.0 , which I refer directly to
Thus, it is obvious that depending on which version of the widget first loaded into the class, we will either have Widget#meow or Widget#bark .
Does Gradle provide any means to help me here? Can I use multiple versions of the same class and configure the fizzbuzz classes to use the old version of widget , and my classes use the new version? If not, the only solutions I can think of are the following:
- Perhaps I can do some kind of shading and / or push based on the game, where maybe I will use all my dependencies as packages under
myapp/bin , and then give them different version prefixes. Admittedly, I do not see a clear solution here, but I'm sure something is possible (but still hacker / nasty). Or... - Inspect the entire dependency graph and just make sure that all of my transitive dependencies do not conflict with each other. In this case, for me, this means either sending a transfer request for
fizzbuzz to update it to the latest version of widget , or, unfortunately, overriding myapp to use an older version of widget .
But Gradle (so far) has been magical to me. So I ask: is there any Gradle magic that can help me here?