Gradle compiles java sources in a dependency jar

I have the following dependencies block defined

dependencies {
 compile "foo:bar:version"
}

It correctly retrieves a jar named bar-version.jar, which contains classes and sources files. When I call “gradle build” I get an error in compileJava task, because a class in bar-version.jar cannot be compiled.

After some research, the java files in bar.jar are recompiled because the java files timestamp is more recent than the class files timestamp. (this was due to a call to format task after having compiled bar JAR)

Why does Gradle try to compile files contained in a dependency ?

By default, the java compiler will compile any source files on the classpath. A strange default for sure :slight_smile: http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html#implicit

You can switch this option off using:

compileJava.options.compilerArgs << '-implicit:none'

http://forums.gradle.org/gradle/topics/why_does_gradle_extract_classes_from_jar_dependencies_into_build_classes

The thing is that when I do not call the format task when I build my “foo:bar:version” dependency, there is no compilation problem. It seems that since the java files in “foo:bar:version” are older than the classes files, they are not recompiled ?