I have an Android app project with separate android library module inside, that is published as a binary. I'd like to add an ability to switch the gradle between building a library from sources or using the published artifact. Android app depends on binary artifact by default :
compile "com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}"
Now I want my binary artifact to be replaced by the source code, so I add the following code in root build.gradle file :
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}") with project(':mylibrary')
}
}
However when I'm trying to build gradle is still taking the binary artifact. What is wrong here?
here is the full source code
Also interesting is that if I move dependency substitution code to allprojects section or to application module build.gradle file, than gradle fails to build with the following message :
Error:Module version MyApplication:app:unspecified, configuration '_debugCompile' declares a dependency on configuration 'default' which is not declared in the module descriptor for MyApplication:mylibrary:unspecified
A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.
Gradle caches artifacts in USER_HOME/. gradle folder. The compiled scripts are usually in the . gradle folder in your project folder.
Finally I've found a working solution. Somehow that works if I do it the other way round. Instead of substitute binary with project module
substitute module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}") with project(':mylibrary')
I can substitute project module with binary :
substitute project(':mylibrary') with module("com.example.konstantin.mylibrary:mylibrary:${mylibraryVersion}")
And than the magic works. The full working code is available on separate branch of an example repo
However that's not an ideal solution, because I have to always link the project module in settings.gradle and can not build without checking it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With