简体   繁体   中英

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");

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM