Parse Gradle Version

Answered

Hi, 

Is there a way to obtain the gradle version the IDE is using within a plugin action?

Thank you!

0
8 comments

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?

0

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.

0

Hi Ryan,

Please try:

GradleProjectSettings projectSettings = GradleSettings.getInstance(project)
    .getLinkedProjectSettings(project.getBasePath())
    .resolveGradleVersion();

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.

0

That worked great Karol! Though there are some projects that return `null` for:

.getLinkedProjectSettings(project.getBasePath())

any idea why that is? 

0

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.

0

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?

0

Also to be clear, it's not the `project.getBasePath()` that's returning null, but rather the `getLinkedProjectSettings` that returns null.

0

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.

0

Please sign in to leave a comment.