boundrates / codeartifact-gradle-plugin

Gradle plugin that configures AWS CodeArtifact repositories as both the source of plugins and the source of project dependencies
Apache License 2.0
10 stars 3 forks source link

misleading documentation #24

Closed pavelpp closed 8 months ago

pavelpp commented 8 months ago

Documentation says "This will add the given repository as a source for Gradle project plugins (settings plugins are not supported) as well as a source for project dependencies." In fact it does not add this repo as source for project dependencies. You can see that if you register a task and run it:

tasks.register("listRepos") {
    doLast {
        project.repositories
            .map { it as MavenArtifactRepository }
            .forEach {
                println("repository name: ${it.name}; url: ${it.url};")
            }
    }
}
rieske commented 8 months ago

Thanks for raising the issue!

The reason that you don't see the repository in the project.repositories is because the plugin configures the CodeArtifact Maven repository not on the project level, but using centralized repositories declaration in the settings. You can find the relevant code here.

You can try declaring the following in the settings.gradle in a fresh project:

dependencyResolutionManagement {
  repositories {
    mavenCentral()
  }
}

and the snippet you shared won't find the Maven Central repository in project.repositories as well. But if you declare dependencies in you build file, they will be resolved from Maven Central.

To prove that codeartifact-gradle-plugin in fact uses the declared CodeArtifact repository as source for project dependencies, you can do the following:

// note, the credentials here are fake, you need to configure real ones for your repo, // otherwise the plugin will fail to authenticate with CodeArtifact codeartifact { domain = "yourdomain" accountId = "123456789012" region = "eu-west-2" repo = "yourrepo" }

- in the `build.gradle`, declare:
```groovy
plugins {
    id("java-library")
}

dependencies {
    implementation("foo:bar:42")
}

And then run: gradle dependencyInsight --dependency foo:bar

You will get a failure, indicating that Gradle looked for this project dependency in the configured CodeArtifact repository:

> Task :dependencyInsight
foo:bar:42 FAILED
   Failures:
      - Could not find foo:bar:42.
        Searched in the following locations:
          - https://yourdomain-123456789012.d.codeartifact.eu-west-2.amazonaws.com/maven/yourrepo/foo/bar/42/bar-42.pom
        If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.