Cannot find symbol dependencyResolutionManagement in GradleSettingsModel
Answered
I am trying to write a plugin that adds my repo to settings.gradle if available or in build.gradle in other cases, like this:
public static void addLibraryRepositories(GradleBuildModel file, GradleSettingsModel settings, String url) {
// Check if settings.gradle contains the repositories
RepositoriesModel repositoryModel = null;
if (settings != null) {
repositoryModel = settings.dependencyResolutionManagement().repositories();
}
// if not use the build.gradle file
if (repositoryModel == null || repositoryModel.repositories().size() <= 0) {
repositoryModel = file.repositories();
}
// add the Tealeaf maven repo
if (!repositoryModel.containsMavenRepositoryByUrl(url)) {
repositoryModel.addMavenRepositoryByUrl(url, "My Repo");
file.applyChanges();
}
}
But I am getting this error when running gradle task 'buildPlugin':
error: cannot find symbol
repositoryModel = settings.dependencyResolutionManagement().repositories();
^
symbol: method dependencyResolutionManagement()
location: variable settings of type GradleSettingsModel
Using IntelliJ 2022.1.3, there is no error on IDE, I can navigate to the definition of the interface and the GradleSettingsModelImpl implementation, in project view I can see it is included in android-gradle-dsl.jar.
I have these deps in plugin.xml
<depends>com.intellij.modules.all</depends>
<depends>com.intellij.modules.java</depends>
<depends>org.jetbrains.android</depends>
<depends>org.intellij.groovy</depends>
I can call other methods of the same class without this error.
Any help is appreciated.
Please sign in to leave a comment.
Hi Hugo,
This method is available from a specific version of the Android plugin. You should set up your plugin project Gradle configuration to target the platform and Android plugin versions that support this method.