Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to adjust the setup to work with private Maven repositories? #66

Open
marcindabrowski opened this issue Nov 25, 2024 · 3 comments
Open
Labels

Comments

@marcindabrowski
Copy link

I'm trying to build this example using private repos - Gradle Plugin Portal, and Maven central are proxied via private Artifactory.

I made these changes:

  • gradle/plugins/build.gradle.kts - replaced gradlePluginPortal() with
        maven {
            url = uri("https://my-artifactory/gradle-plugins")
            credentials {
                username = ...
                password = ...
            }
        }
  • gradle/plugins/src/main/kotlin/org.example.gradle.feature.repositories.settings.gradle.kts - replaced repositories.mavenCentral() with
        maven {
            url = uri("https://my-artifactory/maven")
            credentials {
                username = ...
                password = ...
            }
        }

I tried to add pluginManagement with my gradle plugins repos to settings.gradle.kts but it didn't helped.

I had to change my wrapper url to the link from my artifactory, but is is working.
But I pointed to Gradle 8.11.1 instead of RC of 8.11.

After all this changes I'm getting:

* Where:
Build file '/Users/mdabrows/mda-projects/gradle-project-setup-howto/gradle/plugins/build.gradle.kts' line: 1

* What went wrong:
Plugin [id: 'org.gradle.kotlin.kotlin-dsl', version: '5.1.1'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:5.1.1')
  Searched in the following repositories:
    Gradle Central Plugin Repository

So it has to other place where I have to point not to Gradle Central Plugin Repository but to my artifactory, but not have idea where :(

@jjohannes
Copy link
Owner

jjohannes commented Nov 25, 2024

Yes this is sneaky and we can maybe improve the example to be more explicit about the repositories. To explain:

One "downside" of this setup is that the repositories for plugins need to be defined twice:

  1. For compiling you own plugins (in the context of the gradle/plugins build)
  2. For using the plugins (in the context of the main build)

With the change in gradle/plugins/build.gradle.kts, you made the adjustment for (1).
For(2), you need to adjust the pluginManagement {} block in settings.gradle.kts:

pluginManagement {
    repositories.maven {
        url = uri("https://my-artifactory/gradle-plugins")
        credentials {
            username = ...
            password = ...
        }
    }
    includeBuild("gradle/plugins")
}

The reason this is hidden is that only in this place, and only if you define no custom repositories, Gradle adds gradlePluginPoirtal() by default. The block could look like this and would work the same as it does now:

pluginManagement {
    repositories.gradePluginPortal() // if omitted, this is still added by default
    includeBuild("gradle/plugins")
}

@jjohannes jjohannes changed the title Now working with private repos How to adjust the setup to work with private Maven repositories? Nov 25, 2024
@mqware
Copy link

mqware commented Nov 27, 2024

I tried to add the default block to my project, but I had to modify it slightly to make it work, like this:

pluginManagement {
    repositories {
        gradlePluginPortal() // if omitted, this is still added by default
    }
    includeBuild("gradle/plugins")
}

Or in the more compact form:

pluginManagement {
    repositories.gradlePluginPortal() // if omitted, this is still added by default
    includeBuild("gradle/plugins")
}

Similarly, I think the local repo should be defined as:

pluginManagement {
    repositories {
        maven {
            url = uri("https://my-artifactory/gradle-plugins")
            credentials {
                username = ...
                password = ...
            }
        }
    }
    includeBuild("gradle/plugins")
}

or:

pluginManagement {
    repositories.maven {
        url = uri("https://my-artifactory/gradle-plugins")
        credentials {
            username = ...
            password = ...
        }
    }
    includeBuild("gradle/plugins")
}

@jjohannes
Copy link
Owner

Thank you for double checking @mqware. I adjusted my original answer accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants