i have a problem adding dependencies automatically to eclipse android project via gradle. I have only a little bit experience with gradle. Till now I have build two java projects with gradle. One jar and an executable-jar. This works without problems. I have used the eclipse plugin to generate the eclipse project and add the dependenies to the build path. I added new dependencies to the gradle script, started gradle with gradle eclipse ,update my project and the dependencies exist in the build path and I can used them. Here is the important part of that script.
apply plugin: 'java'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile 'commons-io:commons-io:2.4'
}
So, now I tried it in combination with the android plugin. Here is my hole gradle script.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.1'
}
android {
compileSdkVersion 17
buildToolsVersion "17"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
If I use gradle eclipse nothing happens. Then I found out that the java plugin adds the dependencies to the build path. So I added
apply plugin: 'java'
to it and got the error that the java plugin is not compatible with the android plugin. Then I found a solution to copy the jars automatically to the lib folder of the project.
def libDir = file('libs')
task copyLibs(type: Copy) {
doFirst {
libDir.mkdirs()
}
from configurations.runtime
into libDir
}
But this task needs the java plugin too for the configurations.runtime. I need the android plugin to create the apk file, so it is not a solution to remove the android plugin. Has somebody an idea if it is possible to add the dependencies to the build path or lib folder in ecipse project that is compatible with the android plugin?
EDIT: One of my ideas was to put the java-plugin to the eclipse-plugin, so that it will be only applied when the eclipse plugin will be applied. Something like this:
apply plugin: 'eclipse'
eclipse{
apply plugin: 'java'
}
But I still get the error that the java and android plugins are not compatible. Maybe I understand gradle wrong, but normally the java plugin should be applied only when I start the eclipse plugin and not the android plugin. I´m afraid that my understanding and experience of gradle is not good enough to solve this this way or understand why it is not possible.