Parse Gradle Version
Answered
Hi,
Is there a way to obtain the gradle version the IDE is using within a plugin action?
Thank you!
Please sign in to leave a comment.
Hi Ryan,
Could you please clarify the use case? Do you mean obtaining the Gradle version in your plugin action at runtime in a Gradle project?
Thanks for the response Karol!
Yes that's what I mean. I have a plugin that essentially runs a Gradle command as an action, but if the Gradle version is below X, I want to change the params I pass the command.
So yes, at runtime I want to be able to detect the Gradle version in my plugin action.
Hi Ryan,
Please try:
Also, in order to use Gradle API, you will need to add <depends>org.jetbrains.plugins.gradle</depends> in your plugin.xml and plugins section in https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties.
That worked great Karol! Though there are some projects that return `null` for:
any idea why that is?
Hi Ryan,
I'm sorry I pointed you to this method. Its Javadoc states that it's not recommended to use it and Project.getBaseDir() lists alternatives. Looking at the code of AbstractExternalSystemSettings.getLinkedProjectSettings() it would be reasonable to use a module path, as external protect settings hold modules paths.
Hi Karol,
Where are you seeing this documentation? I'm not seeing any jdoc comments on the method:
What would the full supported method call look like?
Also to be clear, it's not the `project.getBasePath()` that's returning null, but rather the `getLinkedProjectSettings` that returns null.
Hi Ryan,
I was unclear, sorry. I meant that Project.getBasePath() Javadoc states that using it is not a good idea.
You can have a project whose base path is unrelated to any Gradle configuration and in this case settings will be null. Ideally, you should pass a Gradle module path to this method.