This message was deleted.
# community-support
s
This message was deleted.
v
If you are ok with 90% match (figure made up, but definitely below 100)
The files could be missing completely, or they could also be in a subproject, or the root project directory might be configured to be somewhere else by the setting script, ...
If you require Gradle 7.0 at least, you could check for
settings.gradle
or
settings.gradle.kts
as with 7.0 they are mandatory. But even then you just verify that you are in the settings directory, not necessarily the root project directory. But 100% certainty you probably just get by querying the project using the tooling api.
👍 1
j
are you using it on a cli script or on a Gradle task?
i
CLI
v
If it were inside Gradle he would probably just use
rootDir
😄
😂 1
j
yeah, is it mandatory to use CLI instead of a Gradle task?
i
Let me dig into more details of my scenario: I am writing a library that will be verifying structure of the Kotlin project. This lib will be running as JUnit test (obviously written in Kotlin), accessing and verifying Kotlin code base inside this test. The main problem here is to get the Gradle project root dir from JUnit Test (kind of CLI as it is outside Gradle, but truly it is a Java Program). Inside test I can run
Copy code
File("").absoluteFile.path
to get the "current" directory path. This provides path to a source set eg.
.../project/module/src/test
(thus the traversing up approach) After @Javi "CLI question" I am thinking that It may be better to traverse up and try to run Grade command and parse
rootDir
from command output 🤔 (which command would you recommend?) BTW1 I need to explore similar approach for Maven, but this is another story BTW2 I will provide option to manually set root dir, but it would be super convenient for devs to have a method that can simply get all of the kotlin files from the current project (Gradle project root dir)
v
As you are in JVM, probably better follow what I said. Use the tooling API to get information about the build.