Problem adding jars directory to the compile tasks clappath


(Evgeny Dreyman) #1

Hi,
Sorry for this newbie question, but I tried a number of solution from the forum and gradle documents and still seems I am missing something.
I am trying to port some ant task (that works OK) to gradle build.
For the build I have to add all the jar files under some structure to the classpath, like ant’s:

I have defined sourceSet, like below one
sourceSets {
commonLib {
java {
include “${common_lib_dir}/**/.jar"
}
}
}
and add this to the classpath, like:
classpath = sourceSets.commonLib .java
It did not helped. BTW, when I tried to print ${sourceSets.commonLib.java} it gives:
common lib Java source
why ?
I tried also to add the path using dependencies, like
dependencies {
compile files("${common_lib_dir}/
.jar”)
}
but, still the compilation don’t see the jars.
Could somebody clarify what I am doing wrong ?
Thanks in advance.
Evgeny


(Chris Doré) #2

In both of your examples, you are missing a * in front of .jar. Is that just a typo here, or is it also missing in your code?

Try the following:

dependencies {
    compile fileTree( dir: common_lib_dir, include: '**/*.jar' )
}

https://docs.gradle.org/current/userguide/dependency_management.html#sub:file_dependencies
https://docs.gradle.org/current/userguide/working_with_files.html#sec:file_trees


(Evgeny Dreyman) #3

Hi Chris,
Thanks for a quick and constructive reply. Unfortunately, it still does not work for me.
It was just typo in my examples, regarding * in front of .jar


(Evgeny Dreyman) #4

Hi,
Just to clarify the issue - it is solved by using FileTree in task from JavaCompile type:
classpath = fileTree("${common_lib_dir}")