Java plugin fails to compile with empty path

Using the following build.gradle:

apply plugin: 'java'

def srcDirs = file('paths.list').text.readLines()
srcDirs.each { srcDirectory ->
    sourceSets {
        main {
            java {
                srcDir srcDirectory

and paths.list:


Executing ‘gradle build’ fails with the following error message:

Neither path nor baseDir may be null or empty string. path='' basedir='/home/martin/devel/tmp/gradle-srcdirs-from-file'

Gradle Version: 2.14.1
Operating System: Xubuntu 16.04.1
Java: 1.8.0_101 (Oracle Corporation 25.101-b13)

As the error message says, you are trying to add an empty string, probably because your path.list file has a trailing newline.

Oh, I completely missed that, thanks.