Skip to content

Instantly share code, notes, and snippets.

@tmmvn
Created February 10, 2022 13:30
Show Gist options
  • Save tmmvn/85401c3eec9f3a6f5432683fe3695b0d to your computer and use it in GitHub Desktop.
Save tmmvn/85401c3eec9f3a6f5432683fe3695b0d to your computer and use it in GitHub Desktop.
Add .gitignore contents to Gradle file ignores
// Add this to your settings.gradle.kts
// It should likely go after the plugin settings block, which is said to have to be first thing, and before any of your
// includes.
// NOTE: By default, gradle ignores .gitignore. If you plan on using this for zipping or such, you probably want to do
// org.apache.tools.ant.DirectoryScanner.removeDefaultExclude("**/.gitignore")
// too to get the .gitignore in.
try {
val file = File(".gitignore")
val fr = java.io.FileReader(file)
val br = java.io.BufferedReader(fr)
var line = br.readLine()
while (line != null) {
val sb = StringBuffer()
sb.append(line)
val lineString = sb.toString()
if (!lineString.contains('#') && lineString.isNotEmpty()) { // Ignore comments and empty lines
org.apache.tools.ant.DirectoryScanner.addDefaultExclude(lineString)
}
line = br.readLine()
}
fr.close()
}
catch(e: Exception) { // IOException is probs enough here, but whatever
println("Error:$e")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment