I running a logger test that create some logs, and since I want those to be automatically deleted after the test pass or in the next gradle build execution, I would like to output the files into the build gradle folder.
I´ve been looking how to point as relative path the build gradle folder from Java, but I could not find any answer.
My test is in the folder structure
Project->src->main->java
And I would like to output the files into
Project->build
Any idea how to get that relative path?
SOLUTION
String projectPath = System.getProperty("user.dir");
rollingFileAppender.setFile(projectPath + File.separator + "/build/policy_rule_test.log");
Obviously user.dir + '/build' works as you have figured out, but gradle does have a variable for build directory, which is buildDir.
Of these two ways, I would recommend using buildDir just so if a plugin or someone decides to change output directory by setting buildDir, you're still covered for the cleanup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With