jitpack.io
jitpack.io copied to clipboard
Local jar files dependencies are discarded in the artifact deployed by Jitpack
Hi, first of all, my knowledge using Jitpack is very limited (and Maven), so probably the next question is a little dummy.
I have this project, it is a java library project, specifically is the rx_cache module which I'm talking about it. I started using gradle to resolve the “guava” dependency as follow:
dependencies {
compile ’com.google.guava:guava:11.0.2'
}
There were no problem. When requiring the artefact generated by Jitpack, all worked fine.
But I realised that guava increased the total methods count of my library project in about 11.000. This is a problem for a library which most of its potential users could be android developers. So, I downloaded directly the guava jar and I shrank it with proguard. After that, the methods count were down to 1.100. Much better.
But now, in order to resolve the guava dependency, I have a jar file in libs folder, and it is referenced in gradle as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
The library works perfectly well when I reference it from another module in the same project. Or even If I run the test, it is still working. But when I try to use it throughout Jitpack, the jar seems to be not include as reference in the artifact, because I can see that when decompiling the apk file. And for that reason, whatever project that uses my library crashes with the next error:
java.lang.NoClassDefFoundError: Failed resolution of: //several classes
It does not matter what jar I include as dependency. I tried others jars because I thought maybe the problem could be related by the fact that I shrank the jar file with proguard. But It is not the problem, because any jar I include is discarded in the final artifact.
So, my question is how can I retain jar files in my project library in order to prevent they be discarded when Jitpack generates the artifact? I know this is not a problem related with Jitpack, but I don’t know how to resolve it.
Thanks!
Hi Victor!
That's a really good question. You're right, JitPack won't publish jars that you have in your libs folder. Would it be possible to put Guava in a separate GitHub repo and run pro-guard as part of it's build? If it's in a separate repository then it will be usable from your other projects too.
Another option is to publish the jar as part of your project http://stackoverflow.com/a/11505497/4562758 The build file will require some tweaking but happy to work with you on that if you're interested.
Hi! After trying a lot of “exhausting crazy hacking stuff” and not getting any success, I’ve decided to include guava as a maven artifact, instead of a jar.
But now I’ve created a new tag release, “0.3”, but when I tried to download the artifact from another project,
compile "com.github.VictorAlbertos:RxCache:0.3"
the next error shows:
Error:Failed to resolve: com.github.VictorAlbertos:RxCache:0.3
Did I do something wrong?
Thanks!
Hello, Looks like it's getting stuck resolving 'sample_data' project. There is a dependency on the project itself https://github.com/VictorAlbertos/RxCache/blob/master/sample_data/build.gradle#L18
It'd be better to reference the main lib like this:
compile project(':rx_cache')
Thanks!
I’ve moved the sample projects to another repository because I prefer to maintain the dependency pointing to the final artifact, instead of a local project ;)
I'm still interested in this issue.. do you mind to help me out?
I created a stripped down version of a library I need here.
The build.gradle
can be found in the subdirectory jadx-core
.
I got it to build perfectly fine (try with tag v0.6.1-dev), but when running my code I also get the NoClassDefFoundError
. This happens because it needs the dx-1.10.jar library, found in lib. I don't have access to the source code of the dx library (at least not for the exact same version), so creating a new repository for it is not an option.
I've experimented a little bit (following your link) and came up with the following additions to my build.gradle:
artifacts {
archives file: file('lib/dx-1.10.jar'), name: 'dx', type: 'jar'
}
install {
repositories {
mavenInstaller {
addFilter('dx') {artifact, file ->
artifact.name == 'dx'
}
}
}
}
Using these additions it actually does create an artifact for the dx library, however I did not find out how to include the default library then. If I do it this way, it only includes the dx library. So is there a solution which allows me to deploy both of them and get them working nicely together?
EDIT:
So after fiddling around for a long time (and not getting any help here), I finally found a way to do it, so if anyone else is coming here for help, I'd like to let you know how I solved my issue.
What I did was that I edited the jar task as follows:
jar {
baseName = project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
And added the following filters:
install {
repositories {
mavenInstaller {
addFilter('dx') {artifact, file ->
artifact.name == 'dx'
}
addFilter('jadx-core') {artifact, file ->
artifact.name == 'jadx-core'
}
}
}
}
Of course, you'd need to adapt the names to your needs. Now jitpack is able to build the project and includes its jar dependencies.
@jitpack-io, is there a designated way to do this now? @fschrofner's approach works, but creates a fat jar with all dependencies. Unfortunately, all dependencies except the local jars are already included because of the compile statements.
Correct me if I'm wrong, but these steps seem to only work with the maven plugin, which is now deprecated. Anyone know how I achieve the same thing with the maven-publish plugin?
Same problem for me, if I use the library from maven local, it works well, but it throws ClassNotFoundException when it's build from jitpack