Calling gradle sync from Idea plugin programmatically

Answered

Hi

Our plugin overwrites some gradle files, e.g. sets non-default build variants.

How to programmatically call gradle sync from plugin so that the user does not need to manually click on this yellow banner

Unfortunately http://stackoverflow.com/q/28185682 does not help in my case.

Thank you

2
5 comments

You can try the following api: com.intellij.openapi.externalSystem.util.ExternalSystemUtil#refreshProject

ExternalSystemUtil.refreshProject(
project, GradleConstants.SYSTEM_ID, rootProjectPath, false,
ProgressExecutionMode.IN_BACKGROUND_ASYNC);

 

0

For me

ActionManager am = ActionManager.getInstance();
AnAction sync = am.getAction("Android.SyncProject");
sync.actionPerformed(e);

worked perfectly fine for Android Studio and it perfectly suits my purpose.

"ExternalSystem.RefreshAllProjects" 

also worked somehow even with the Idea, but it updated the build variants only when I clicked on these to change.

Спасибо!

1

Vladislav Soroka: In latest APIs GradleConstants is not present. Can you share updated snippet please?

0

org.jetbrains.plugins.gradle.util.GradleConstants is part of Gradle plugin

0

ExternalSystemUtil.refreshProject(
  project, GradleConstants.SYSTEM_ID, rootProjectPath, false,
  ProgressExecutionMode.IN_BACKGROUND_ASYNC);

Brings the problem: requires plugin 'com.intellij.gradle' to be installed

Altough i have:

plugin.xml: <depends>com.intellij.gradle</depends>
and build.gradle.kts: 

intellij {
    version.set("2023.1.3")
    type.set("IC") // Target IDE Platform

    plugins.set(listOf("java", "com.intellij.java", "com.intellij.gradle"))
}

0

Please sign in to leave a comment.