lucky1928
lucky1928

Reputation: 8925

Change gradle default directory to project directory

In below sample, the file name output will be at home directory, how can I change the default directory to current project directory?

 tasks.register('hello')  {
  doLast {
    String dirname = "demo";
    String filename = "hello.txt";

    String abspath = new File(dirname, filename).getAbsolutePath();
    System.out.println(abspath);
  }
}

Current output is:

/home/user/.gradle/daemon/7.4.2/demo/hello.txt

But what I want is:

/project/path/demo/hello.txt

Upvotes: 0

Views: 869

Answers (1)

Opal
Opal

Reputation: 84864

What you're looking for is project.getRootDir() - it points to the project's root dir.

Upvotes: 2

Related Questions