Exclude unneccesarry jar in FAT jar using gradle - 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

Related

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

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

gradle plugin provide classpath depedencies

In my plugin I am using couple of external dependencies
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
compile "commons-io:commons-io:$commonsIoVersion"
// tar & xz support
compile "org.tukaani:xz:$xzLibraryVersion"
compile "org.apache.commons:commons-compress:$commonsCompressVersion"
// logging
compile "io.github.microutils:kotlin-logging:$kotlinLogginVersion"
compile "org.slf4j:slf4j-simple:$slf4jSimpleVersion"
When I use my plugin I have to provide them as classpath dependencies
classpath "org.tukaani:xz:$xzLibraryVersion"
classpath "commons-io:commons-io:$commonsIoVersion"
classpath "org.apache.commons:commons-compress:$commonsCompressVersion"
classpath "com.lapots.gradle.plugins.appenv:gradle-app-environment-plugin:0.1"
classpath "io.github.microutils:kotlin-logging:$kotlinLogginVersion"
Is there a way to escape from it? I mean to allow to set only my plugin dependency and other it provides itself?
ext.commonDeps = [
"org.tukaani:xz:$xzLibraryVersion",
"commons-io:commons-io:$commonsIoVersion",
"org.apache.commons:commons-compress:$commonsCompressVersion",
"com.lapots.gradle.plugins.appenv:gradle-app-environment-plugin:0.1",
"io.github.microutils:kotlin-logging:$kotlinLogginVersion"
]
buildscript.dependencies {
classpath commonDeps
}
dependencies {
compile commonDeps
}

How can I clone a repo from GitHub using gradle?

I have a project which depends on other repos. My goal is to write a gradle task that clones the required repos automatically.
The problem I am having is that when I run my task, gradlew fails because it tries to compile the project dependencies before running my task. Here is what I have:
settings.gradle
include ':app'
include 'testRepo'
project(':testRepo').projectDir = new File('../testRepo')
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.ajoberstar:gradle-git:1.5.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle(app)
task clone << {
Grgit.clone(dir: file('../testRepo'), uri: "https://github.com/fakeAccount/testRepo.git")
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':testRepo')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
}
When I do ./gradlew clone I get:
"Cannot evaluate module testRepo : Configuration with name 'default' not found"
This is because it tries to compile the testRepo project before cloning from GitHub. If I take out the compile project(':testRepo') it works fine.
Any ideas as to how to make this work?

Android Studio 2.2: Gradle: Fixplugin version and sync project

Gradle problem
I"m update build.gradle:
`}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
and
gradle-wrapper.propertie:`
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
app\build.gradel:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
}
Location C:/Software/gardle2.14/gradle-2.14
I"m get this note:
Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "f45c7e54f5c7108ea208060be3303c44dd2ae899"
Thanks for support

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.

Resources