Groovy Documentation

org.gradle.api.artifacts
[Java] Interface ModuleDependency

org.gradle.api.artifacts.Dependency
  org.gradle.api.artifacts.ModuleDependency
All Superinterfaces:
Dependency

public interface ModuleDependency
extends Dependency

A ModuleDependency is a Dependency on a module outside the current project.

For examples on configuring the exclude rules please refer to exclude(java.util.Map).


Field Summary
 
Fields inherited from interface Dependency
ARCHIVES_CONFIGURATION, CLASSIFIER, DEFAULT_CONFIGURATION
 
Method Summary
ModuleDependency addArtifact(DependencyArtifact artifact)

DependencyArtifact artifact(Closure configureClosure)

ModuleDependency copy()

{@inheritDoc}

ModuleDependency exclude(Map excludeProperties)

Adds an exclude rule to exclude transitive dependencies of this dependency.

Set getArtifacts()

Returns the artifacts belonging to this dependency.

String getConfiguration()

Returns the configuration of this dependency module (not the configurations this dependency belongs too).

Set getExcludeRules()

Returns the exclude rules for this dependency.

boolean isTransitive()

Returns whether this dependency should be resolved including or excluding its transitive dependencies.

ModuleDependency setTransitive(boolean transitive)

Sets whether this dependency should be resolved including or excluding its transitive dependencies.

 
Methods inherited from interface Dependency
contentEquals, copy, getGroup, getName, getVersion
 

Method Detail

addArtifact

public ModuleDependency addArtifact(DependencyArtifact artifact)

Adds an artifact to this dependency.

If no artifact is added to a dependency, an implicit default artifact is used. This default artifact has the same name as the module and its type and extension is jar. If at least one artifact is explicitly added, the implicit default artifact won't be used any longer.

Returns:
this


artifact

public DependencyArtifact artifact(Closure configureClosure)

Adds an artifact to this dependency. The given closure is passed a DependencyArtifact instance, which it can configure.

If no artifact is added to a dependency, an implicit default artifact is used. This default artifact has the same name as the module and its type and extension is jar. If at least one artifact is explicitly added, the implicit default artifact won't be used any longer.

Returns:
this


copy

public ModuleDependency copy()
{@inheritDoc}


exclude

public ModuleDependency exclude(Map excludeProperties)
Adds an exclude rule to exclude transitive dependencies of this dependency.

Excluding a particular transitive dependency does not guarantee that it does not show up in the dependencies of a given configuration. For example, some other dependency, which does not have any exclude rules, might pull in exactly the same transitive dependency. To guarantee that the transitive dependency is excluded from the entire configuration please use per-configuration exclude rules: Configuration#getExcludeRules()#getExcludeRules(). In fact, in majority of cases the actual intention of configuring per-dependency exclusions is really excluding a dependency from the entire configuration (or classpath).

If your intention is to exclude a particular transitive dependency because you don't like the version it pulls in to the configuration then consider using forced versions' feature: ResolutionStrategy.force.

 apply plugin: 'java' //so that I can declare 'compile' dependencies

 dependencies {
   compile('org.hibernate:hibernate:3.1') {
     //excluding a particular transitive dependency:
     exclude module: 'cglib' //by artifact name
     exclude group: 'org.jmock' //by group
     exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
   }
 }
 
Parameters:
excludeProperties - the properties to define the exclude rule.
Returns:
this


getArtifacts

public Set getArtifacts()
Returns the artifacts belonging to this dependency.
See Also:
addArtifact(DependencyArtifact)


getConfiguration

public String getConfiguration()
Returns the configuration of this dependency module (not the configurations this dependency belongs too). Never returns null. The default value for the configuration is DEFAULT_CONFIGURATION. A dependency source might have multiple configurations. Every configuration represents a different set of artifacts and dependencies for this dependency module.


getExcludeRules

public Set getExcludeRules()
Returns the exclude rules for this dependency.
See Also:
exclude(java.util.Map)


isTransitive

public boolean isTransitive()
Returns whether this dependency should be resolved including or excluding its transitive dependencies.
See Also:
setTransitive(boolean)


setTransitive

public ModuleDependency setTransitive(boolean transitive)
Sets whether this dependency should be resolved including or excluding its transitive dependencies. The artifacts belonging to this dependency might themselve have dependencies on other artifacts. The latter are called transitive dependencies.
Parameters:
transitive - Whether transitive dependencies should be resolved.
Returns:
this


 

Gradle API 1.12