简体   繁体   English

从java获取gradle构建路径文件夹

[英]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. 我运行了一个创建一些日志的记录器测试,因为我希望在测试通过后或在下一个gradle构建执行中自动删除它们,我想将这些文件输出到build gradle文件夹中。

I´ve been looking how to point as relative path the build gradle folder from Java, but I could not find any answer. 我一直在寻找如何指向Java的build gradle文件夹的相对路径,但我找不到任何答案。

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 . 显然user.dir + '/build'可以解决,但是gradle确实有一个构建目录的变量,即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. 在这两种方式中,我建议使用buildDir ,如果插件或某人决定通过设置buildDir来更改输出目录,那么你仍然需要进行清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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