How to only fetch dependency of a certain Type (jar for instance)?

Recently ran into an issue where my build generated a faulty package without failing.
The corporate Nexus repo was accidentally updated by someone, so that a source code .zip package overwrite the Jar file I depended on.
That is, my dependency declaration:

runtime ([group: 'org.jboss.marshalling', name:'jboss-marshalling', version:'1.4.3.Final'])

started generating RPM files containing a source code Zip file instead of the necessary jar. Of course, we got a runtime error from the class loader.

In Maven, we could declare something like this, which would have instead given me a build error - unable to resolve the dependency. Much preferable.


I tried doing the same in Gradle, but there seems to be no “type” attribute, at least not in Gradle 2.4:

   runtime ([group: 'org.jboss.marshalling', name:'jboss-marshalling', version:'1.4.3.Final', type:'jar'])

* What went wrong:
A problem occurred evaluating project ':myproject'.
> No such property: type for class: org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency_Decorated
Possible solutions: name

I can’t find anything on this in the User’s Guide.

The equivalent is ext which can be done via the @ character if using the String dependency notation.


dependencies {
    runtime "org.groovy:groovy:2.2.0@jar"
    runtime group: 'org.groovy', name: 'groovy', version: '2.2.0', ext: 'jar'

You may instead choose to use a classifier

See the documentation here

Thanks! Just what I was looking for.