Parse and Modify gradle file

Hello,

 

I am trying to build a plugin for Android Studio as a part of which I will have to modify the project's build.gradle file. Is there a PSI class similar to PsiJavaFile which can be used for parsing and modifying the gradle file effectively?

 

Thanks in advance

1
3 comments
Avatar
Permanently deleted user

Hi Avinash. I have the same question - did you have any luck with this?

0
Avatar
Permanently deleted user

Yes I was able to get this to work. 

You will have to use the class import com.android.tools.idea.gradle.parser.GradleBuildFile and a bunch of other objects related to this class and you will be able to get reference of gradle file, modify it and apply the changes. 

Source code of this file ie. https://android.googlesource.com/platform/tools/adt/idea/+/630f33fd7919534b3fd0bbe87be0e2b5c3f9922b/android/src/com/android/tools/idea/gradle/parser/GradleBuildFile.java  should be able to give you more idea about what this class can offer. Let me know if you need any further help, based on your use case, I can get you the sample code if required. 

 

PS : Haven't worked on this in a while, but I don't think anything would have changed. 

0
Avatar
Permanently deleted user

Hi Avinash, thank you very much for your answer!

I am not able to import the package com.android.tools and anything within it into my plugin. What dependency did you declare for IntelliJ to find the classes?

0

Please sign in to leave a comment.