How to resolve external maven dependencies with custom POM dependency scopes?

I’m having some difficulty retrieving artifacts which use custom dependency scopes in our external POM files.

I understand Gradle uses maven libraries as a means to fetch external maven dependencies.

I also understand that from Maven’s perspective, Maven POM files can only use a specific set of dependency ‘scopes’

– compile, runtime, etc.

Like several other posters, we have a need to define and use some custom dependency scope in our maven POM files. For example, ‘manifest’ scope and ‘release’ scope.

I am able to use Gradle to publish these dependencies with custom POMs using these scopes.

However, I am having difficulty getting Gradle to download dependencies with a specified scope.

So far in my experimentation, Gradle downloads the specified ‘compile’ config dependency and any other dependencies listed in its POM file, even when their scopes do not match the gradle configuration (‘compile’).

I would like to be able to align the gradle configuration with the maven pom scopes evaluated during dependency resolution.

So for example, if I am using the compile configuration in Gradle, only ‘compile’ scope artifacts would be retrieved.

However, what I am seeing happen is that although my Gradle dependency uses compile config, the artifacts downloaded (transitively) have all sorts of different scopes in the maven poms.

Is there a way to restrict which artifacts are downloaded, say by applying scope filters somehow to the set of artifacts to download?

An example might be helpful.

Say I have an external maven artifact com.foo:bar:1.0.168 which has a pom like this

...
  <groupId>com.foo</groupId>
  <artifactId>bar</artifactId>
  <version>1.0.168</version>
  <dependencies>
    <dependency>
      <groupId>com.foo</groupId>
      <artifactId>bar-manifest</artifactId>
      <version>1.0.30</version>
      <scope>manifest</scope>
    </dependency>
  </dependencies>
...

In my build.gradle, I have this block:

dependencies {
  compile 'com.foo:bar:1.0.168'
}
  task fetchArtifacts << {
  copy {
    from configurations.compile
    into "lib"
  }
}

When I run ‘gradle fetchArtifacts’ it downloads not just com.foo.bar:1.0.168 but also all dependencies listed in com.foo.bar-manifest:1.0.30, with various maven pom dependency scopes such as ‘release’, ‘compile’, and ‘manifest’.

I would like to retrieve only the compile dependencies – com.foo.bar:1.0.168 and any other compile dependencies listed in com.foo.bar-manifest:1.0.30.

Any thoughts?

Thanks! -Steve

Maven dependency management doesn’t support custom scopes. (Your POMs are invalid.) If you need custom scopes, you’ll have to use Ivy dependency management.

Did you ever solve this? We are thinking about adding a custom scope for our end-to-end testing and what you are asking for is exactly what’s needed.

We found this to be a major limitation, so we ended up

a) disabling transitive downloads for compile scope (which we did not really need),

b) no longer linking from the artifact to the ‘manifest’ – rather, ‘manifest’ is a reserved artifact name in the same groupid as the artifact itself.

c) crafting our own non-maven manifests in gradle to track the information we want tracked, and we push them when we publish component artifacts.

Logically, I think this is similar to using ivy.