java.util.zip.ZipException: duplicate entry: com/google/common/annotations/Beta.class - gradle

This error occurred while running my project, unable to run my application for the build.
I have clean the build and rebuild the project again results in same problem.
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/common/annotations/Beta.class
I have shared my gradle file below. Kindly help me to find the changes to be done in gradle file to run my application.
Gradle File
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.5.0#aar') {
transitive = true;
}
compile 'com.uber.sdk:rides-android:0.5.3'
compile 'com.twitter.sdk.android:twitter:3.1.1'
compile project(':branchsdk')
compile project(':squarecamera')
compile 'com.google.code.gson:gson:2.5'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.facebook.rebound:rebound:0.3.8'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
compile 'se.emilsjolander.stickylistheaders:library:2.1.0'
compile ('com.android.support:support-v4:26.0.0')
{ exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude module: 'support-annotations'
}
compile ('com.android.support:appcompat-v7:26.0.0'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'com.android.support'
}
compile 'com.github.siyamed:android-shape-imageview:0.9.2'
compile 'com.adobe.creativesdk.foundation:auth:0.5.3'
compile 'com.adobe.creativesdk.foundation:assets:0.5.3'
compile 'com.adobe.creativesdk:image:4.0.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile ('com.google.android.gms:play-services:11.6.2'){
exclude group: 'com.google.guava'
}
compile 'com.parse:parse-android:1.10.2'
compile 'org.altbeacon:android-beacon-library:2.5.1'
compile 'org.apache.commons:commons-collections4:4.0'
compile 'org.solovyev.android.views:linear-layout-manager:0.5#aar'
compile 'de.greenrobot:eventbus:2.4.0'
compile ('com.android.support:recyclerview-v7:26.0.0')
{
exclude group: 'com.android.support'
}
compile ('com.android.support:multidex:1.0.1')
{
exclude group: 'com.android.support'
}
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'me.relex:circleindicator:1.2.2#aar'
compile 'com.google.firebase:firebase-config:11.6.2'
compile 'com.google.firebase:firebase-messaging:11.6.2'
compile project(':ucrop')
compile project(':library')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.google.guava:guava:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
Kindly help me to solve this problem.
Thanks in Advance...

I think you're getting stung by the Google collections rename to guava and you probably have both on your classpath.
See Using module replacement rules
Eg:
dependencies {
modules {
module("com.google.collections:google-collections") {
replacedBy("com.google.guava:guava", "google-collections is now part of Guava")
}
}
}
Or another problem could be this
fileTree(include: ['*.jar'], dir: 'libs')
The jars in this libs folder can't participate in dependency resolution because there's no meta-data (eg group/artifact/version) so it's possible that there are duplicates here too
See here to store local jars in a maven directory layout instead

Related

CompileJava failed to find metamodel and failed

I've has a project for at least a year and would compile fine. now when i try to compile the metamodels are missing and the compilejava task is failing. I'm not sure if the issues is because there is a version issue or what. keep in mind that before hand i had no issue with running the build with the current gradle build script and project file structure.
the code is in java with netBeans:
Product Version: NetBeans IDE 8.2 (Build 201609300101)
Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2
Java: 1.8.0_171; Java HotSpot(TM) 64-Bit Server VM 25.171-b11
Runtime: Java(TM) SE Runtime Environment 1.8.0_171-b11
System: Windows 10 version 10.0 running on amd64; Cp1252; en_US (nb)
Gradle Support 1.4.4
i've attempted to "set the generated path" but that didn't work.
i've also tried to create me own copies of the metamodel class then reference it in the dynamic query builder. it would compile but the when i tested the query and i keep getting a null pointer exception.
if i ctrl click the metamodel in the class file using the metamodel it loads the metamodel class file i think there is some issue with the generator creating the metamodel object on compile.
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
war.archiveName "ApplicationWarehouseService.war"
war {
webInf {from 'src/main/resources/application.xml' }
}
if (!hasProperty('mainClass')) {
ext.mainClass = 'test'
}
repositories {
mavenCentral()
maven {
url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"
}
}
dependencies {
compile 'javax.servlet:javax.servlet-api:4.0.0'
compile 'commons-validator:commons-validator:1.6'
compile 'org.springframework:spring-webmvc:5.0.5.RELEASE'
compile 'org.springframework.security:spring-security-web:5.0.4.RELEASE'
compile 'org.springframework.security:spring-security-config:5.0.4.RELEASE'
compile 'org.springframework:spring-jdbc:5.1.6.RELEASE'
compile 'org.springframework:spring-aop:5.1.6.RELEASE'
compile 'org.springframework:spring-context:5.1.6.RELEASE'
compile 'org.springframework:spring-context-support:5.1.6.RELEASE'
compile 'org.springframework.data:spring-data-jpa:2.1.6.RELEASE'
compile 'org.springframework:spring-orm:5.1.6.RELEASE'
compile 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8'
compile 'org.hibernate:hibernate:3.5.4-Final'
compile 'org.hibernate:hibernate-core:5.4.2.Final'
compile 'org.hibernate:hibernate-jpamodelgen:5.4.3.Final'
compile 'org.aspectj:aspectjrt:1.9.0'
compile 'org.aspectj:aspectjweaver:1.9.0'
compile 'org.apache.tomcat:tomcat-jdbc:9.0.7'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
compile 'commons-fileupload:commons-fileupload:1.3.3'
compile 'javax.mail:javax.mail-api:1.6.1'
compile 'javax:javaee-api:8.0'
compile 'javax.servlet:jstl:1.2'
compile 'org.hibernate.validator:hibernate-validator:6.0.9.Final'
compile 'org.apache.logging.log4j:log4j-core:2.11.0'
compile files('C:/Program Files (x86)/Microsoft JDBC Driver 4.1 for SQL Server/sqljdbc_4.1/enu/jre7/sqljdbc41.jar')
//compile 'com.lowagie:itext:4.2.2'
compile 'com.lowagie:itext:2.1.7'
compile 'net.sf.jasperreports:jasperreports:6.1.0'
// compile 'com.itextpdf:itextpdf:5.5.13'
// compile 'net.sf.jasperreports:jasperreports:6.5.1'
compile 'javax.money:money-api-bp:1.0'
compile 'org.json:json:20180130'
compile 'javax.xml.bind:jaxb-api:2.3.0'
compile group: 'ar.com.fdvs', name: 'DynamicJasper', version: '5.1.1'
compile group: 'ar.com.fdvs', name: 'DynamicJasper-core-fonts', version: '1.0'
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile 'org.springframework:spring-test:5.0.5.RELEASE'
}
configurations.all*.dependencies*.withType(ModuleDependency)*.each {
it.exclude group: "org.bouncycastle", module: "*"
it.exclude group: "bouncycastle", module: "*"
}
ideally i'd like to have my project create the metamodels and compile successfully.
I found the Solution I Added
annotationProcessor('org.hibernate:hibernate-jpamodelgen:5.4.3.Final')
in the dependencies section. Compiled just fine.

Error building project while excluding transitive dependency in build.gradle file

I am creating a multi module project with Spring Boot for deploying my application and using gradle as my build tool.
Now, I am creating independent deployments for some modules in the project. Some of the project requires Embedded tomcat and some do not. All the common dependencies have been put on a common project and all other modules are dependent on this common project.
Most of the other deployment modules require an embedded tomcat application server and other web components (provided by org.springframework.boot', name: 'spring-boot-starter-web) so this has been included in the build.gradle for common project
Here is the build.gradle for common project:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion
Now, one of the other modules which is going to be deployed independently does not require this embedded tomcat and other mvc jars which comes with including spring-boot-starter-web but requires the other transitive dependencies from common project. As such, I want to exclude the transitive dependency for
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
I am doing it like this in the build.gradle other project
dependencies {
compile project(':common') {
exclude group 'org.springframework.boot', module:'spring-boot-starter-web'
}
}
But while building it is throwing this error:
startup failed: build file
'/Users/user1/Documents/repo/storm/build.gradle': 30: expecting '}',
found ',' # line 30, column 44.
oup 'org.springframework.boot', module:'
changing it to:
dependencies {
compile project(':common'){
exclude group 'org.springframework.boot:spring-boot-starter-web'
}
}
throws:
Could not find method exclude() for arguments [parent-project name] on
project ':common'.
How can I exclude transitive dependency here?
You need to invoke exclude on compile not on project:
dependencies {
compile(project(':common')) {
exclude group: 'org.springframework.boot', module:'spring-boot-starter-web'
}
}

could not find method compile() for arguments

I'm trying to execute some .sql scripts and then deploy web app using gradle tomcat plugin.
But when I make any attempt to run gradle I've got an error
My buildscript looks like this
buildscript {
//repository location
repositories {
mavenCentral()
jcenter()
}
//dependencies
//did not divide them into runtime&compile
dependencies {
//aspectJ dependencies
compile 'org.aspectj:aspectjlib:1.6.2'
compile 'org.aspectj:aspectjrt:1.7.4'
compile 'org.aspectj:aspectjweaver:1.7.4'
//servlet
compile 'javax.servlet:javax.servlet-api:3.0.1'
//jdbc postresql
compile 'org.postgresql:postgresql:9.2-1004-jdbc4'
//commons dbcp
compile 'commons-dbcp:commons-dbcp:1.2.2'
//spring & spring MVC dependencies
compile 'org.springframework:spring-core:' + spring_version
compile 'org.springframework:spring-web:' + spring_version
compile 'org.springframework:spring-webmvc:' + spring_version
compile 'org.springframework:spring-jdbc:' + spring_version
compile 'org.springframework:spring-aspects:' + spring_version
//spring security
compile 'org.springframework.security:spring-security-core:' + spring_security_version
compile 'org.springframework.security:spring-security-web:' + spring_security_version
compile 'org.springframework.security:spring-security-config:' + spring_security_version
//JSTL
compile 'jstl:jstl:1.2'
//slf4j-log4j
compile 'org.slf4j:slf4j-api:1.7.0'
compile 'org.slf4j:slf4j-log4j12:1.7.0'
compile 'log4j:log4j:1.2.17'
//mybatis
compile 'org.mybatis:mybatis:3.2.4'
compile 'org.mybatis:mybatis-spring:1.2.2'
//gson
compile 'com.google.code.gson:gson:2.2.4'
//validation jsr303
compile 'javax.validation:validation-api:1.0.0.GA'
//junit4(test?)
compile 'junit:junit:4.11'
//spring test(test?)
compile 'org.springframework:spring-test:' + spring_version
//java mail
compile 'javax.mail:mail:1.4'
//tomcat plugin
def tomcatVersion = '7.0.53'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
//additional classpath
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.3'
classpath 'org.postgresql:postgresql:9.2-1004-jdbc4'
}
}
In build.gradle there are also several tasks and several apply plugin.
What's the problem? Full stack trace
My build.gradle is in a project folder.
The build script is mixing up buildscript dependencies (i.e.
dependencies of the build itself; typically this means Gradle plugins
with regular dependencies (i.e. dependencies of the code to be compiled/run).
2 needs to go into dependencies { ... }, not into buildscript { dependencies { ... } }.
Everything but the classpath dependencies are regular dependencies.
I get this error sometimes after Android Studio does some operation that tries to automatically add things to my build.gradle file, and then it messes up lines of code in the dependencies block that end with quotes or double-quotes. So I end up with a line like this:
def gpsVersion = '9.4.0'
compile "com.google.android.gms:play-services-wearable:${gpsVersion}" compile "com.google.android.gms:play-services-places:${gpsVersion}"
And as you can see it looks like the method compile has many arguments now. Fix the line spacing and resync to fix it.

Exclude unneccesarry jar in FAT jar using gradle

I am building the FAT jar using gradle-1.3 version and building the
FAT jar using this below properties
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it)
}
Dependencies AS FOLLOWS
dependencies {
compile fileTree(dir:'/trunk/Solutions/Seismic/Source/Binaries/CommonFunctions/build/libs', include: '*.jar')
compile "org.apache.hadoop:hadoop-core:1.0.3"
compile "commons-collections:commons-collections:3.2.1"
compile "commons-configuration:commons-configuration:1.6"
compile "commons-discovery:commons-discovery:0.2"
compile "commons-lang:commons-lang:2.4"
compile "commons-logging:commons-logging:1.1.1"
compile "commons-logging:commons-logging:1.0.4"
compile "log4j:log4j:1.2.16"
compile "com.vividsolutions:jts:1.8"
compile "commons-net:commons-net:1.4.1"
compile "org.apache.hadoop:hadoop-core:1.0.3"
compile "commons-httpclient:commons-httpclient:3.0.1"
compile "org.mortbay.jetty:servlet-api:2.5-20081211"
compile "org.apache.hbase:hbase:0.94.0"
compile "org.apache.zookeeper:zookeeper:3.4.3"
}
But still by jar is included with following jar as reference
jay,
jline,
jni,
jnr,
jruby,
junit,
junit3.8.1
But i don't want to include these jars
You can exclude the dependencies by adding this to the bottom of your build:
configurations.all*.dependencies*.withType(ModuleDependency)*.each {
it.exclude group: "org.jline", module: "jline"
it.exclude ...
}
This will iterate over the dependencies of all configurations and exclude the modules that you don't want to include.
If you want to exclude all transitive dependencies, it is easier to set the transitivity to false for the compile configuration:
configurations.compile.transitive = false

how to exclude jar from fileTree in upstream projects?

We have the following configuration in a project...
configurations {
//compile.exclude module: 'commons'
//all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
all*.exclude module: 'log4j'
}
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.6.6'
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.protobuf',name: 'protobuf-java', version: '2.4.1'
//compile group: 'org.asteriskjava',name: 'asterisk-java', version: '1.0.0.M3'
//to be erased soon
compile group: 'commons-configuration',name:'commons-configuration',version: '1.8'
//compile group: 'org.bouncycastle', name: 'bcpg-jdk16', version: '1.46'
compile project(':sdi-master')
compile project(':sdi-webserver')
}
unfortunately, the project sdi-webserver has it's own log4j brought in from a filetree like so
project(':sdi-webserver') {
project.ext.genLibDir = file('lib')
dependencies {
compile project(':sdi-master')
compile fileTree(dir: '../webserver/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework', include: 'play-*.jar')
}
How do we exclude this jar so it is not part of the dependencies. The above excludes that we have only works for repositories and transitive dependencies and doesn't work for fileTree, but we still need to somehow exclude the jar file as we want eclipse task building correct .classpath, we want configurations.compile having accurate info for copying jars, etc. etc.
thanks,
Dean
Simply use an exclude on fileTree. Syntax is the same as for include.

Resources