When downloading dependencies using Gradle it seems to exclude optional dependencies. For example, I included Guava:
compile 'com.google.guava:guava:19.0'
and it did not download the optional dependencies listed here: https://mvnrepository.com/artifact/com.google.guava/guava/19.0
I've been learning Gradle and porting a legacy app to use Gradle. That application had a Python script wrapper that always downloaded the optional dependencies and I've kind of hit a wall here.
According to the description of the Maven's Optional Dependencies:
If a user wants to use functionality related to an optional dependency, they will have to redeclare that optional dependency in their own project.
Gradle has the same behavior as Maven, if you want to use some transitive optional dependencies - you have to declare them manually.
You can try to find some workaround, but anyway, it seems to be a little odd, to include all optional dependencies by default, don't even check, whether are they really needed. Sure, you can try to port your logic to run existent Python script with Gradle to collect all optional dependencies into local directory and declare it as file dependencies.
Related
I am trying to add the following dependency to my Gradle build file:
compile 'org.eclipse.scout.sdk.deps:org.eclipse.core.resources:3.10.+'
This package depends on a lot of other packages, that are located in the same repository. The problem is that for some reason, Gradle deems them unworthy. Here's an example of the errors I've been getting:
Could not find any version that matches org.eclipse.scout.sdk.deps:org.eclipse.equinox.common:[3.7.0,3.7.1).
Versions that do not match:
3.7.0.v20150402-1709
Note that 3.7.0.v20150402-1709 does match [3.7.0,3.7.1)
Some additional technical details:
I'm working on Gradle v. 2.11.
This dependency, as well as its' dependencies, are located in the following repository:
https://repo1.maven.org/maven2/
Edit 1:
Yes, I could just exclude the transitive dependencies and add them with the correct version numbers, but it's such a horrible solution I can't bring myself to write it down. Hoping someone out there has an elegant solution.
How to write a gradle script so that the application jar should be packed without dependency classes similar to maven jar package
The application JAR is always without dependencies, except you use special plugins to create a "fat" JAR where the dependencies are included. If you ask how to set up a Gradle build at all, you should start reading the Users Guide.
If you are trying to package a jar from your Android app or library:
I ran into this question because gradle would include 3rd party libraries into my jar when running gradle assembleRelease.
The contents of the jar then looked like this:
com/android/...
/myCompany/...
For some reason this did not happen when building for debug. Finally I found that changing:
compile 'com.android.support:recyclerview-v7:23.0.0'
to
provided 'com.android.support:recyclerview-v7:23.0.0'
would not include the 3rd party libs ...
I am not MavenĀ“s user and i want configure all dependencies of Swagger in my project. I try make it unsucessful. I get thousands jars, jackson-, swagger- and nothing.
From https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X#adding-the-dependencies-to-your-application:
Projects that cannot utilize maven's dependencies would need to add
the dependencies manually. Since those may change from version to
version, the list of dependencies will not be documented here.
Instead, it is advised that you clone the swagger-core repository, go
to the directory of the relevant module (artifact) and run mvn dependency:list. That would give you a list of dependencies required
by swagger-core which you would have to include manually in your
application. Keep in mind this requires you to have maven installed
but it does not require you to use maven for your project.
I want to pass the dependency-x.y.z-sources.jar that gradle downloads as a parameter to another plugin (specifically j2objc )
Is there a way to have a reference to the downloaded source jar?
I assume you are using the gradle j2objc plugin? See here. In short, you need to make sure the gradle compile dependency you add specifies a specific version (no + or unspecified) and that the specified dependency provides a -sources.jar. After that, if you add autoConfigureDeps true to the top of your j2objcConfig closure it will pick up the sources.
We are new to Gradle and dependency resolution. I am in the process of creating pom.xml files for all our internally-generated artifacts and want to set up a job in our Jenkins server to verify the dependencies are properly defined and not conflicting (i.e. LibA requires x-1.0.jar, LibB requires x-1.1.jar, and AppY requires both LibA and LibB).
As such, I've set up a dummy project in SVN that simply includes a bunch of our internal artifacts as dependencies. Following TTD, I intentionally included some errors in the declarations (i.e. group and name, but not version). Sure enough, those dependencies can't be found.
But when I run this build with gradle (i.e. gradle dependencies) it includes all the failure messages but still says the build succeeded! Not good!
How can I, using Gradle/Jenkins, set up an automated job that will verify all dependencies are found?
There is no built-in task that resolves all dependencies and fails if a dependency isn't found. (IDE tasks are graceful in case of missing dependencies.) But you can easily write your own:
task resolveDependencies {
doLast {
configurations.all { it.resolve() }
}
}
gradle dependencies by design displays Gradle project dependencies reporting (if applicable) if given dependency cannot be resolved (a red text FAILED next to an unresolved dependency). To get an error use some task that depends on resolving dependencies for given configuration(s) like gradle check.
Updated. Gradle is smart in determining if given tasks are required to be executed. Therefor in case there is no source files to compile (compilation requires dependent classes/JARs to be resolved) gradle check can notice that executing compileJava/compileTestJava tasks is not needed (tasks are skipped as up-to-date). You can force it by adding any Java source file into src/main/test (tests requires also production dependencies (from compile configuration)).
This is just a workaround, there is probably a better way to do that (and I hope someone else will present it here).