Need to read a list of values from file and use it scrDir

I have a list file ex: paths.list

it file contains paths

paths.list

/hai1/src
/hai2/src
/hai2/src

I want to read this file in my build.gradle and need these values(3 paths) to be used in my source sets as below

sourceSets {
main {
java {
srcDirs = [’/hai1/src’,’/hai2/src’,’/hai3/src’]
}
}
}

I want these srcDirs should be updated with the list in file,

How can I achieve this.

Assuming paths.list is in the project directory, try something like this

srcDirs = file( 'paths.list' ).collect { it }