# Adding a plugin with dependencies of a specific maven repository

**URL:** <https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406>\
**Category:** Plugin Portal\
**Tags:** not-a-bug\
**Created:** [November 8, 2018, 3:43pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406 "2018-11-08T15:43:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [November 8, 2018, 3:43pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/1 "2018-11-08T15:43:21Z")

</div>

Hi,

I have to make a gradle plugin to use our own builder. This builder have some “common” dependencies (from jcenter) and some other from our own m2 public repository ([https://m2.convertigo.com](https://m2.convertigo.com)).

I tested my plugin by publishing to maven local. In an another project, I have to declare 3 repositories in order to get it work:

```
buildscript {
    repositories {
        jcenter()
        maven {
            url "https://m2.convertigo.com"
        }
        mavenLocal()
    }
    dependencies {
        classpath 'org.samples.greeting:greeting-plugin-example:0.1'
    }
}

apply plugin: 'org.samples.greeting'

```

Next, I read the doc about publishing to the plugin-portal and I though we can publish / remove plugin directly and I didn’t think there is an “approuval” step and no button to remove it.

Can you remove my test please : com.github.nicolas-albert.greeting ?

I have to know if once published, extra dependencies will be pulled from “[https://m2.convertigo.com](https://m2.convertigo.com)” or the user have to add this repository itself ? (like the method without plugin-portal)

Also, do I publish the plugin with my personnal account for my compagny or do I have to create “corporate” account to do this (if someone else have to publish a release) ?

Thanks !

---

<div class="post-metadata">

**Author:** ![eriwen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eriwen/32/4786_2.png) [@eriwen](https://discuss.gradle.org/u/eriwen)\
**Post date:** [November 8, 2018, 4:34pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/2 "2018-11-08T16:34:23Z")

</div>

Hi Nicolas,

I’ve removed your test plugin as requested. It doesn’t look like there’s a way to delete a new, unapproved plugin yet.

The build script you posted here will get dependencies only for _building the plugin itself_ and does _not_ declare that consumers of the plugin should have that repository declared. The user would have to add the repository themselves. However, there’s a way to add repositories to a `Project` in the `Plugin<Project>` class.

We recommend creating a corporate account for publishing so that access is shared. Currently there’s not a mechanism to allow multiple owners for a given plugin.

Cheers,  
Eric

---

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [November 8, 2018, 4:50pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/3 "2018-11-08T16:50:22Z")

</div>

Thanks Eric,

Do you have an url or a github repo with the good pratice about adding a repository with the `Plugin<Project>` ?

I suppose this is something like that but I didn’t find a complet sample:

```
public class GreetingPlugin implements Plugin<Project> {
    public void apply(Project project) {
        project.getBuildscript().getRepositories().add(??);

```

I’ll create an account for my company.

Thanks again !

Nicolas

---

<div class="post-metadata">

**Author:** ![eriwen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eriwen/32/4786_2.png) [@eriwen](https://discuss.gradle.org/u/eriwen)\
**Post date:** [November 8, 2018, 5:06pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/4 "2018-11-08T17:06:37Z")

</div>

Nearly correct.

You want `project.repositories.add(...)` in your `apply` method.

Cheers,  
Eric

---

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [November 8, 2018, 5:17pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/5 "2018-11-08T17:17:15Z")

</div>

I don’t know what to put in place of `...`, how can I transform DSL

```
maven {
    url "https://m2.convertigo.com"
}

```

to a java object ?

I found the `DefaultMavenArtifactRepository` class but the constructors aren’t simple to complete \>.\<

```
new DefaultMavenArtifactRepository(fileResolver, transportFactory, locallyAvailableResourceFinder, instantiatorFactory, artifactFileStore, pomParser, metadataParser, authenticationContainer, moduleIdentifierFactory, resourcesFileStore, fileResourceRepository, featurePreviews, metadataFactory, isolatableFactory, objectFactory)
new DefaultMavenArtifactRepository(describer, fileResolver, transportFactory, locallyAvailableResourceFinder, instantiatorFactory, artifactFileStore, pomParser, metadataParser, authenticationContainer, moduleIdentifierFactory, resourcesFileStore, fileResourceRepository, featurePreviews, metadataFactory, isolatableFactory, objectFactory)

```

I think I have missed something.

---

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [November 8, 2018, 8:25pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/6 "2018-11-08T20:25:15Z")

</div>

I think I have the right syntax but it’s still fail if I remove my repo from the testing app buildscript section.

```
public class GreetingPlugin implements Plugin<Project> {
    public void apply(Project project) {
        RepositoryHandler repo = project.getRepositories();
        repo.maven((maven) -> {
	        maven.setUrl(URI.create("https://m2.convertigo.com"));
        });
        repo.jcenter();

```

The gradle of the testing app search for my plugin dependencies in my mavenLocal repo and ignore repositories declared in the apply.

I also tested this without success:

```
repo.add(repo.maven((maven) -> {
    maven.setUrl(URI.create("https://m2.convertigo.com"));
}));

```

Thanks for your support.

---

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [November 9, 2018, 10:25am UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/7 "2018-11-09T10:25:06Z")

</div>

Here a sample of my gradle for the plugin:

```
plugins {
    id 'java-gradle-plugin'
    id 'maven-publish'
    id 'com.gradle.plugin-publish' version '0.10.0'
}

apply plugin: 'java'

group = 'org.samples.greeting'
version = '0.1'

repositories {
    jcenter()
    maven {
        url "https://m2.convertigo.com"
    }
}

dependencies {
    compile 'commons-lang:commons-lang:[2.6,)'
    compile 'com.convertigo.lib:convertigo-engine-api:7.6.0-SNAPSHOT'
}

gradlePlugin {

```

It compile, publish locally, wonderful.

But when I use it, the apply isn’t called because the dependencies are unknow for my maven local.

So I change `compile` to `compileOnly` and then the `apply` is called. I can add repositories but I cannot add dependencies : `Cannot change dependencies of configuration ':classpath' after it has been resolved.`

I still not know how a plugin can use dependencies of a custom repository and I didn’t find sample or documentation about this.

Some help will be appreciate.

---

<div class="post-metadata">

**Author:** ![StefMa](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefma/32/9384_2.png) [@StefMa](https://discuss.gradle.org/u/StefMa)\
**Post date:** [December 4, 2018, 12:39pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/8 "2018-12-04T12:39:11Z")

</div>

So lets summarize:  
You want to create a **public** Gradle Plugin which will add your custom repo so that a user can define a dependencies from that repo, right?

If so, then you code above “works”.  
As @eriwen mentioned [above](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/4?u=stefma) you only have to add the repo via `project.repositories.add` (or like you do with `repo.maven(...)`.

Your problem is that **your plugin** define a dependency which is inside the custom repo.  
So you have to imagine that Gradle do the following:

- Apply your plugin
- Wants to resolve its dependencies **-\> Error**
- Call apply after resolving of the dependencies was successfully.

How could you resolve this?  
Well, when your plugin **really** needs the `convertigo-engine-api` as dependency than your clients **have to** declare your custom repo. Otherwise it is “not really possible” - At least from what I know about Gradle 😄.

Another thing is when you want to add a dependency **in your Plugin** for your “users”.  
In other words, when you want to provide a Plugin which will add some dependencies for the **current project**.  
Then you can simply call the code above (to add the **repo** ) and then add the dependency via [`project.dependencies.add()`](https://docs.gradle.org/5.0/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html#add-java.lang.String-java.lang.Object-).  
Then Gradle should know how to resolve the dependency from the custom repo…

---

<div class="post-metadata">

**Author:** ![nicolas-albert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/nicolas-albert/32/6227_2.png) [@nicolas-albert](https://discuss.gradle.org/u/nicolas-albert)\
**Post date:** [December 13, 2018, 3:15pm UTC](https://discuss.gradle.org/t/adding-a-plugin-with-dependencies-of-a-specific-maven-repository/29406/9 "2018-12-13T15:15:28Z")

</div>

I tried many many things 1 month ago without success and I went forward.  
In all case, we provide a gradle file in the template of our new projects and it use the “old” syntax, but does the job:

```
buildscript {
	repositories {
		mavenLocal()
		maven {
			url "https://m2.convertigo.com"
		}
		jcenter()
	}
	dependencies {
		classpath 'com.convertigo:gradle-plugin:((CURRENT_VERSION))'
	}
}

apply plugin: 'convertigo'

```

Thanks for your answer.
