Hi, I’m making a Gradle plugin. I need to specify ...
# gradle
j
Hi, I’m making a Gradle plugin. I need to specify a custom maven repository, but this doesn’t work. Is there any other way?
Copy code
class TestPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        with(project) {
            repositories {
                maven(url = uri("<https://maven.pkg.jetbrains.space/public/p/compose/dev>"))
            }
            dependencies {
                add(PLUGIN_CLASSPATH_CONFIGURATION_NAME, "land.sungbin:composable.reference.suppressor.plugin:1.0.0")
            }
        }
    }
}
v
Please don't, or at least make it optional. Well, if it is just some internal plugin it might be ok. But if you make it public, it is very bad practice to add repositories from a plugin. If for example someone wants or needs (company guidelines) all repositories where things are downloaded from and maybe even configures to fail on additional repositories, your plugin will not be usable.
Besides that, what do you mean by "doesn't work", what do you expect to happen and what happens instead?
j
I expected Jetbrain Maven to be added and download “org.jetbrains.compose.compiler” which is a dependency referenced in “composable.reference.suppressor.plugin”. But the download of “composable.reference.suppressor.plugin” failed because JetBrain Maven was not added. (Could not find “org.jetbrains.compose.compiler” referenced internally) And thanks for the advice! I plan to use this plugin for internal use in my project.
v
What is the exact error message?
w
Are you sure that transitive dependency is hosted in that repo?
j
The error that occurred is:
Copy code
> Could not find org.jetbrains.compose.compiler:compiler:1.3.2-alpha01.
  Searched in the following locations:
    - <https://dl.google.com/dl/android/maven2/org/jetbrains/compose/compiler/compiler/1.3.2-alpha01/compiler-1.3.2-alpha01.pom>
    - <https://repo.maven.apache.org/maven2/org/jetbrains/compose/compiler/compiler/1.3.2-alpha01/compiler-1.3.2-alpha01.pom>
    - <https://plugins.gradle.org/m2/org/jetbrains/compose/compiler/compiler/1.3.2-alpha01/compiler-1.3.2-alpha01.pom>
  Required by:
      project :playground > land.sungbin.composable.reference.suppressor:land.sungbin.composable.reference.suppressor.gradle.plugin:1.0.3 > land.sungbin:composable.reference.suppressor.plugin:1.0.3
But I’m a little confused right now. Obviously, I was getting errors until I asked this question, but I’ve tried rebuilding it to give you the error message and it’s worked. The above error is from my past build log. At the time of asking the question, I built using the plugin distributed in Maven, but to reproduce the error for you, I moved the code locally and built it using the local. Could this be why adding my repository didn’t work? If you want to see the project code, you can see it here.
Are you sure that transitive dependency is hosted in that repo?
Sure. Compose Compiler dependency is hosted in the JetBrain repository.
w
I see in your error, it was trying to get an alpha version instead of the one you specified
v
The whole plugin class looks fishy. I assume you try to apply the plugin in your
playground
plugin? The dependency that is missing is a dependency of your plugin. You cannot add a dependency your plugin needs in the actual code of the plugin, that's a hen-and-egg situation. Also that plugin adds the repository to the repositories for production code, not for plugins. As you can see from the error message, the searched repositories are
google()
,
mavenCentral()
, and
gradlePluginPortal()
which you most probably configured as plugin repositories in your
playground
projects settings script. There you need to add the JB repository so that your plugin dependencies can be resolved.
j
You cannot add a dependency your plugin needs in the actual code of the plugin, that’s a hen-and-egg situation. Also that plugin adds the repository to the repositories for production code, not for plugins.
Ah, now I know the reason. Thank you so much! In addition, thanks to you, I learned a new expression: “hen-and-egg situation”. 😉