Created
February 10, 2022 13:30
-
-
Save tmmvn/85401c3eec9f3a6f5432683fe3695b0d to your computer and use it in GitHub Desktop.
Add .gitignore contents to Gradle file ignores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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