Duplicates class found in modules - gradle

Duplicate class javax.el.ArrayELResolver found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1)
Duplicate class javax.el.BeanELResolver found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1)
Duplicate class javax.el.BeanELResolver$BeanProperties found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1)
Duplicate class javax.el.BeanELResolver$BeanProperty found in modules jsp-api-2.1-6.1.14.jar (org.mortbay.jetty:jsp-api-2.1:6.1.14) and jsp-api-2.1.jar (javax.servlet.jsp:jsp-api:2.1)
build.gradle:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//The dependencies below are for a library i'm including after which i get the error
compile "org.bouncycastle:bcprov-jdk15on:1.54"
compile "org.apache.pdfbox:pdfbox:[2.0.15,)"
compile "org.mapdb:mapdb:3.0.4"
compile "com.google.guava:guava:19.0"
compile "com.carrotsearch:java-sizeof:0.0.5"
compile "org.apache.hadoop:hadoop-common:2.7.1"
compile "com.amazonaws:aws-java-sdk:1.11.19"
compile "org.apache.hadoop:hadoop-core:1.2.1"
compile "org.apache.lucene:lucene-analyzers-common:6.1.0"
compile "org.apache.poi:poi-scratchpad:3.15-beta1"
compile "org.apache.poi:poi:3.15-beta1"
compile "org.apache.poi:poi-ooxml:3.15-beta1"
I've read on other threads on stack overflow about using the exclude:group in your build.gradle it's just that i seem to be doing something wrong. Can someone please tell me (i) how to add the exlude statement to the fix the error above instead of giving some generic example (ii) how would i manually remove the modules causing the duplication? (i've tried by removing them from the gradle cache folder even deleted the .gradle folder but it keeps rebuilding it). Any suggestion would be appreciated

Firstly compile should be replaced with implementation as it is deprecated. (i) this link provides a good explanation: https://discuss.gradle.org/t/how-to-exclude-transitive-dependency/2119/2
(ii) I searched a lot to find a workable way to go about doing this and most of the suggested methods failed. What actually worked was the following example:
Note: duplicate definition of program class
Problem: hadoop-common and hadoop-core shared numerous common classes that were causing conflict
Solution:
I managed to solve it by manually removing the duplicate .class files in the jar file. (i.e.
(i) changing the extension from jar to zip
(ii) extract it
(iii) remove the .class files or the entire folder if it contains all the duplicate files
(iv) change the extension from zip back to jar
Note do not extract the jar files with Winrar and try to zip them back, for some odd reason that doesn't work. I had to
navigate to the Gradle cache: C->Users-> Username -> .gradle -> caches -> modules-2 -> files-2 -> org.apache.hadoop ->
find either hadoop-common or hadoop-core and apply the above to delete the folders with duplicate classes

Related

How to use Afterburner.fx with Gradle instaed of Maven 3, while leaving the original project structure of afterburner.fx

afterburner.fx for JavaFX 8 is a minimalistic (3 classes) JavaFX MVP framework based on Convention over Configuration and Dependency Injection created by Adam Bien.
afterburner.fx use Maven 3.
I would like to use it with Gradle.
How to use Afterburner.fx with Gradle instaed of Maven 3, while leaving the original project structure of afterburner.fx ?
In the build.gradle File add dependencies
dependencies {
compile group: 'com.airhacks', name:'afterburner.fx', version: afterburnerfxVersion
}
In the build.gradle File add the additional Resources (.fxml , .css , .properties)
sourceSets.main.resources.srcDirs("src/main/java").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties"])
and (re-)add all the standard Resources (in the resources folder)
sourceSets.main.resources.srcDirs("src/main/resources").includes.addAll(["**/*.*"])
Update for Gradle Version 6.8.1 : if you run gradlew with --warning-mode all there is a deprecated Message:
Copying or archiving duplicate paths with the default duplicates strategy has been deprecated. This is scheduled to be removed in Gradle 7.0.
Solution
add this line:
// from https://docs.gradle.org/6.8.1/userguide/upgrading_version_5.html#implicit_duplicate_strategy_for_copy_or_archive_tasks_has_been_deprecated
// and https://docs.gradle.org/current/userguide/java_plugin.html
// Java Plugin Task processResources(type: Copy)
processResources.duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
Thanks, this helped me a lot. I added the short form of it to dependencies:
compile 'com.airhacks:afterburner.fx:1.6.0'
Additionally I added a second line to include the files from the resources folder and not only from /java. I also added **/*.png to include png files because new Image("filename.png") wasn't working anymore.
sourceSets.main.resources.srcDirs("src/main/java").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties", "**/*.png"])
sourceSets.main.resources.srcDirs("src/main/resources").includes.addAll(["**/*.fxml", "**/*.css", "**/*.properties", "**/*.png"])
I don't know why the above two lines broke the default behavior - seems like I have to add every new file type to the above lines. :/ If anyone has a better solution please tell me.

Cannot resolve symbol TexturePacker

Using libgdx 1.7.0/Android Studio, TexturePacker is supposed to be included out of the box if checking the tools option when creating the project (and so I did).
In fact, if I check my build.gradle file, in the project(":desktop") section I have the compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion" added.
But even with that, the build is not able to find the tools package (even though I can successfully use the Controllers extension, which should be the same I think)
I'll leave here the desktop part of the build.gradle, just in case:
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
}
}
And a image with the libraries in the project, where you can see the tools...
This is an issue caused by importing tools in Core Dependency. Remove the dependency in the project(":desktop") of the Core Dependency and add it to desktop dependency.
You can also solve it by downloading the gdx tools and importing the jar file. Just create a library folders and paste the jar file. Then go to File > Project Structure > Modules and add the File Dependency which is your jar file.
dependencies {
compile files('libs/runnable-texturepacker.jar')
}
This should work fine.
I was trying to use the TexturePacker class within a class in the core module. However I discovered it to only be available in the desktop module.
This seems logical as the dependency of the tools extension is placed within the desktop project in the root build.gradle file when using the setup utility or following the official instructions to add the extension manually (see Add tools dependency).
Technically, you could move the dependency in the module you want to use TexturePacker in (say core), but according to the provided link this is discouraged. So I recommend you just write your class using TexturePacker within the desktop module.
PS: Note that due to the deprecation of "compile" a replacement by "implementation" in build.gradle might become necessary, but Android Studio will inform you in that case (use ctrl + r for efficient replacements).

Gradle build error with Simpleframework

I upload my library module to jcenter and I use this module with my application project.
I try to build my application it returns an error.
I searched this issue and This issue is due to be aware of what simpleframework.
I have to use this library both My library module and application module.
How can I solve this problem?
Gradle error msg is below
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when
not building a core library. This is often due to inadvertently
including a core library file in your application's project, when
using an IDE (such as Eclipse). If you are sure you're not
intentionally defining a core class, then this is the most likely
explanation of what's going on. However, you might actually be trying
to define a class in a core namespace, the source of which you may
have taken, for example, from a non-Android virtual machine project.
This will most assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform. It is
also often of questionable legality. If you really intend to build a
core library -- which is only appropriate as part of creating a full
virtual machine distribution, as opposed to compiling an application
-- then use the "--core-library" option to suppress this error message. If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application will
still fail to build or run, at some point. Please be prepared for
angry customers who find, for example, that your application ceases to
function once they upgrade their operating system. You will be to
blame for this problem. If you are legitimately using some code that
happens to be in a core package, then the easiest safe alternative you
have is to repackage that code. That is, move the classes in question
into your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help you
in this endeavor. If you find that you cannot do this, then that is an
indication that the path you are on will ultimately lead to pain,
suffering, grief, and lamentation. 1 error; aborting Error:Execution
failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\jdk1.7.0\bin\java.exe'' finished with non-zero exit value 1
My library build.gradle dependencies are below.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile ('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
}
My Application dependencies are below :
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:5.+'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'commons-io:commons-io:2.4'
compile 'commons-net:commons-net:3.3'
compile 'org.apache.httpcomponents:httpmime:4.2.5'
/*compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}*/
compile 'org.jsoup:jsoup:1.7.2+'
compile 'com.effectivelife:cokcok-support:1.0.0'
}
I solved this problem.
I add a configurations to my application project.
So my application build.gradle file is below.
configurations {
compile.exclude module: 'stax'
compile.exclude module: 'stax-api'
compile.exclude module: 'xpp3'
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:5.+'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'commons-io:commons-io:2.4'
compile 'commons-net:commons-net:3.3'
compile 'org.apache.httpcomponents:httpmime:4.2.5'
compile 'org.jsoup:jsoup:1.7.2+'
compile 'com.effectivelife:cokcok-support:1.0.1'
}

how to add a local android lib to gradle build?

I have an android library (source) that I have been using in eclipse and i need to port to android studio. I have the library building as its own project. but now i want to use it in another project (somewhere else on the filesystem).
How can i declare this library project to my other project. I don't want to copy the files over but rather use it in place. so it cant be under the other project dir hierarchy.
Hope it make sense. If you need more info let just ask. possibly i have to add stuff to publish it as an artifact? when i was using maven i would declare it as a module with a file path ....
tried
repositories {
flatDir {
dirs 'path'
}
}
but to no avail ...
may get diff results with diff gradle versions but i've done this on 1.10...
gradle.settings
include '..:youLib'
AndroidManifest for your lib...
make sure its minimal and it does not contain "ActivityName" or "launcher" props
build.gradle
dependencies {
compile project(':..:youLib')
You need to declare libraries in dependencies section:
E.g.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}

Android studio include aar dependency

I'm trying to add ActionbarSherlock as dependency using line I got from gradleplease
(Instead of these methods. At least according to this link:
"In Gradle you no longer need to add in these libraries as source code projects; you can simply refer to them as dependencies, and the build system will handle the rest; downloading, merging in resources and manifest entries, etc. For each library, look up the corresponding AAR library dependency name (provided the library in question has been updated as a android library artifact), and add these to the dependency section."
this setup should not be necessary anymore)
But it doesn't work and module settings in Android studio shows error: "Library 'ComActionbarsherlockComActionbarsherlock440.aar': Invalid classes root"
Any idea?
Add these line in your module build.gradle
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}

Resources