ActionBarSherlock and swipelistview using gradle - gradle

I need to use ActionBarSherlock and SwipeListView in my project. I added following dependencies to build.gradle file:
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
I get following error: Attribute xxx has already been defined. I suppose that problem is because SwipeListView uses appcompat-v7 as a dependency and ActionBarSherlock and v7 are not compatible as you can see here.
What's the proper way to use both ActionBarSherlock and SwipeListView in my project using gradle?

I excluded the appcompat-v7 lib during build. It seems to work so far. But I'm afraid it might crash on some devices
compile ('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
exclude module: 'support-v4'
exclude module: 'appcompat-v7'
compile 'com.android.support:support-v4:13.0.0'
}
I have opened an issue: https://github.com/47deg/android-swipelistview/issues/191 to see if the dependency is needed or not.

Related

How to excplude module cxf-rt-transports-http

I have the following dependency in build.gradle:
compile ('org.apache.cxf:cxf-bundle:2.4.2') {
exclude module: 'log4j-over-slf4j'
}
I would like to also exclude the module that contains transports-http because of a conflict between libraries (using HTTPConduit). I tried to exclude it, but I don't think I have the right module name
The dependencies task will give you a dependency report where you can see what transitive dependencies are being pulled in.
./gradlew dependencies --configuration compileClasspath
If you were to examine the output of that task, you'll see that org.apache.cxf:cxf-bundle does not appear to bring in cxf-rt-transports-http. So you'll need to examine your project to figure out where the duplicate dependency is.
Gradle also offers a means to handle version conflicts as well: https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html#sec:resolving-version-conflict

Exclude a class depedency in compile, but include in testCompile for gradle

I'm having an issue where I have an old version of library Foo as a transitive dependency in one of my included libs. I want to use a newer version of library Foo in my testCompile, but it's causing a conflict when I run tests in intelliJ, as intelliJ is defaulting to using the older Foo lib.
I've tried excluding Foo, and then explicitly including it in testCompile, but it seems the exclude overrides the include in testCompile.
I'm currently using the below to force a resolution, but I would prefer I don't force compile dependencies to a specific version.
configurations.all {
resolutionStrategy {
force 'org.foo:bar:1.0'
}
}
You might consider configuring idea.module.scopes.TEST like so:
idea {
module {
scopes.TEST.minus += ['org.foo:bar:0.9-oldversion']
}
}
and then running gradle cleanIdea idea. You could also consider modifying the testClasses configuration such that the old version is excluded.

Gradle trump providedCompile's exclusion?

I've got a project that I want to use providedCompile with to avoid pulling it's libs. However, that prevents me from pulling in another project's libs that I do need. The docs say: If you don't want this transitive behavior, simply declare your provided dependencies, but it doesn't give an example of how to do this.
Here's basically what my dependencies look like:
dependencies {
compile(project(':common'))
providedCompile(project(':projA')) // <-- also depends on :common
}
My war file correctly excludes all of transitive libs from projA, but I need to trump that for the common.jar and I can't figure out how to make that happen. But the docs seem to indicate it's possible...
Edit: Here's a hacky configuration that seems to work. The combination of lines for "projA" gives me projA.jar as a dependency, but not its children. And since "common" is a compile dependency, but "projA" is only considered provided at runtime, I still get the common.jar due to the compile time dependency. I'm not sure it's supposed to work this way, but it generates the war I need.
dependencies {
compile(project(':projA')) { transitive = false }
providedRuntime(project(':projA')) { transitive = false }
compile(project(':common'))
}
If you don't want this transitive behavior, simply declare your provided dependencies
This means that if you don't want all dependencies of projA to be declared provided you need to list them as provided one by one.
From the Gradle 1.8 Userguide '26.4. Dependency management'
The War plugin adds two dependency configurations: providedCompile and
providedRuntime. Those configurations have the same scope as the
respective compile and runtime configurations, except that they are
not added to the WAR archive. It is important to note that those
provided configurations work transitively.
Let's say you add commons-httpclient:commons-httpclient:3.0 to any of
the provided configurations. This dependency has a dependency on
commons-codec. This means neither httpclient nor commons-codec is
added to your WAR, even if commons-codec were an explicit dependency
of your compile configuration. If you don't want this transitive
behavior, simply declare your provided dependencies like
commons-httpclient:commons-httpclient:3.0#jar.
There is another better solution that seems to be working. With transitive=false you exclude all the transitive dependencies that are then missing during compilation time and you have to declare all of them manually (again as provided) which is pain if they also include your desired library.
So for the providedCompile statement exclude not all transitive dependencies but only the one you want to include in war by separate compile statement.
Real example where I need the commons-codec included in the war file but that one is placed also in the keycloak-services and keycloak-model-jpa:
providedCompile ("org.keycloak:keycloak-model-jpa:6.0.1") {
exclude group: 'commons-codec', module: 'commons-codec'
}
providedCompile ("org.keycloak:keycloak-services:6.0.1") {
exclude group: 'commons-codec', module: 'commons-codec'
}
providedCompile "org.keycloak:keycloak-core:6.0.1"
providedCompile "org.keycloak:keycloak-server-spi:6.0.1"
providedCompile "org.keycloak:keycloak-server-spi-private:6.0.1"
compile "commons-codec:commons-codec:1.10"

Android Studio importing library Gradle: error: package org.simpleframework.xml does not exist

I can't make project in Android Studio.
When compile project I have some errors:
Gradle: error: package org.simpleframework.xml does not exist
Gradle: error: cannot find symbol class Element
Gradle: error: cannot find symbol class Element
I add jar manually and from Dependencies to project.
How to fix it ?!
OK, I fix It.
The problem was solved. I add manually to config file library libs/simple-xml-2.7.jar.
dependencies {
compile files('libs/android-support-v4.jar', 'libs/commons-net-3.3.jar', 'libs/simple-xml-2.7.jar')
}
You could also use Maven to declare that dependency in your build.gradle, like this:
dependencies {
[...]
compile 'org.simpleframework:simple-xml:2.7'
}
also make sure that you have maven central declared as a repository:
repositories {
[...]
mavenCentral()
}
Another common solution if you want to download the .jars by yourself is to include any .jar inside libs/, like that:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
[...]
}
Anyway, make sure that you don't include a library more than once, that could cause problems.

Resolve Gradle Transitive Dependency Conflict with file system libs (ie. not maven, ivy)

We have a java project with dependencies that looks something like this.
A -> B -> httpcore-4.0.1
\
C -> httpcore-4.1.3
So there is transitive dependency conflict in A. The gradle docs say that the resolution policy is to select the newest (http://gradle.org/docs/current/userguide/dependency_management.html). However, we get compile errors due to function signature differences so the latest doesn't seem to be selected. I've seen various exclude methods but not sure how they apply when we are using a file system based dependency lib (not maven or ivy). Eclipse seems to resolve the problem okay and compile but gradle barfs. I've tried various forms of:
configurations {
all*.exclude group:'org.apache', name: 'httpcore', version:'4.0.1'
all*.exclude group:'org.apache.httpcomponents', name: 'httpcore', version:'4.0.1'
}
What am I missing here?
I'm using Gradle 1.0-milestone-8a
It's just not done. See http://forums.gradle.org/gradle/topics/resolve_gradle_transitive_dependency_conflict_with_file_system_libs_ie_not_maven_ivy
You have to use a local or remote repos.

Resources