Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get gradle build path folder from java

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");
like image 599
paul Avatar asked Oct 30 '22 09:10

paul


1 Answers

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.

like image 182
RaGe Avatar answered Nov 15 '22 04:11

RaGe