Install dependency into Gradle project with disabled Android plugin programmatically

Answered

Hello!

Sometimes I need to install a dependency into user project programmatically.

I use the inheritors of JavaProjectModelModifier for that, method addExternalLibraryDependency. In most cases AndroidJavaGradleProjectModelModifier is used for Gradle projects. However, when user disables Android plugin in his project, this modifier can't be used any more. 

When IdeaProjectModelModifier is used, it installs the dependency into Idea project model, but does not modify Gradle scripts.

How can I install a dependency into Gradle project with the disabled Android plugin via intellij.openapi?

0
1 comment

Please take a look at


com.intellij.externalSystem.DependencyModifierService

it should be available in IDEA 2021.1 and later. This service delegates to proper build system (Maven or Gradle) under the hood. It should work regardless of Android plugin state.

 

0

Please sign in to leave a comment.