How to reuse a filtered sourceset from another subproject

I’d like to include a source folder from a project into another, but excluding some files

I have tried the following build :

project('client') {
      sourceSets {
        main {
            java {
                source project(':core').sourceSets.main.java
                exclude 'some/path/to/exclude/**'
            }
        }
     }
}

But this does not work. The exclude filter is applied only the the source files from the folder of the project itself and not the ‘imported’ source folder.

The following seems to work during compilation but not for the javadoc task :

project('client') {
      sourceSets {
        main {
            java {
                source project(':core').sourceSets.main.java
            }
        }
     }
       sourceSets.main.java.filter.exclude 'some/path/to/exclude/**'
}

I had to add this to make it work with javadoc

javadoc {
    source = sourceSets.main.java
}

Is there some better way of doing what I’m trying to do ?