Java compile errors when jar task has include closure

Until recently I had a jar task definition like this:
jar {
exclude ‘**/*.xml’
For some reason we didn’t want to include Xml files from ‘src/main/resources’.

This policy changed, and it was decided to just include one of the multiple Xml files. So I changed the jar definition like this:
jar {
exclude '**/*.xml’
include ‘src/main/resources/job-universalimport-aktionen.xml’

Now, this resulted in compile errors! The compiler complained about not finding classes from another subproject. First, this led me to find the cause of the problem in some changed java sources or changed gradle properties. Nothing caused this problem. So I changed the jar task to this
jar {
exclude ‘/job-control*.xml’
exclude '
and the compile errors went away. (That is: I could not say exclude-all-xml but include-specific-xml.)

I tested with Gradle 2.4.1 and Gradle 3.0. Maybe it is naive to think that the jar task definition should not influence compile dependencies? After all, this is not a compile dependency definition.

Hi Carlo,

There is a connection between the jar task configuration and compile dependencies when you work with subprojects: The classes compiled in one subproject are provided to others via a jar file which is assembled by the jar task. The include / exclude pattern use the same semantics as defined in ANT File Sets (see:

As soon as you use any include, the default include all is removed. Thats why

jar {
  exclude '*/.xml' 
  include 'src/main/resources/job-universalimport-aktionen.xml'

excludes all Java class files as well. You would need to add them to the include part (e.g. include */.class). Also, in this example, the exclude ‘*/.xml’ has no effect.