# How can I exclude certain java files from being compiled?

**URL:** https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287
**Category:** Old Forum Archive
**Created:** [September 6, 2011, 6:30pm UTC](https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287 "2011-09-06T18:30:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)
#### Post date: [September 6, 2011, 7:03pm UTC](https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287/2 "2011-09-06T19:03:00Z")

</div>

The source set is what specifies what source is to be compiled, and you can configure that with something like:

```gradle
sourceSets {
    main {
        java {
            srcDir 'src'
            exclude ' **/uncompilable/**'
       }
   }
}

```

(A little bit about source sets [here](http://gradle.org/current/docs/userguide/java_plugin.html#N1176B))

Here we are configuring the java [SourceDirectorySet](http://gradle.org/current/docs/javadoc/org/gradle/api/file/SourceDirectorySet.html) of the main [SourceSet](http://gradle.org/current/docs/javadoc/org/gradle/api/tasks/SourceSet.html), which is what is used as the description of what to compile.

Take a look at the documentation for [PatternFilterable](http://gradle.org/current/docs/javadoc/org/gradle/api/tasks/util/PatternFilterable.html) (which is the interface that SourceDirectorySet) implements for all the different ways that you can exclude/include files in the source.

---

_[View the full topic](https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287)._
