`gradlePluginPortal` missing from RepositoryType in RepositoryModel

已回答

Hi,

 

I am building an Android Studio plugin that can inject dependencies into an Android project's build.gradle file. I am using `GradleBuildModel` and calling `gradleBuildModel.buildscript().repositories().repositories()` to get a list of `RepositoryModel`s that exist.

 

However, since `gradlePluginPortal()` is not one of the types for `RepositoryModel` (see https://github.com/JetBrains/android/blob/16d17317f2c44ec46e8cd2180faf9c349d381a06/gradle-dsl/src/com/android/tools/idea/gradle/dsl/api/repositories/RepositoryModel.java#L22-L28), it is not found in the following example, and the list contains only 2 entries for `google()` and `mavenCentral()`.

 

My plugin needs to add `gradlePluginPortal()` if it does not already exist. I think `gradlePluginPortal` should be added as one of the `RepositoryType`s. Otherwise, can you suggest what I can do instead?

 

```groovy
buildscript {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
}
```

 

Thanks so much

0

indeed, gradlePluginPortal is not supported yet, thank you. I've created https://youtrack.jetbrains.com/issue/IDEA-294722

As a workaround for now, you can use raw dsl elements, something like this:

boolean isGradlePluginPresent = ((RepositoriesModelImpl)repositoriesModel)
.getRawElement()
.getChildren().stream()
.filter(e ->
(e instanceof GradleDslMethodCall) &&
((GradleDslMethodCall)e).getMethodName().equals("gradlePluginPortal"))
.findAny().isPresent()


and add like this

((RepositoriesDslElement)repositoriesModel.getRawElement())
.addParsedElement(
new GradleDslMethodCall(repositoriesModel.getRawElement(), GradleNameElement.empty(), "gradlePluginPortal"));



0

请先登录再写评论。