Skip to content

Commit

Permalink
Ignore artifact when relocation exists in pom
Browse files Browse the repository at this point in the history
This fixes gradle#1789

When <relocation> element exists in pom, both original artifact
(if it exists) and relocated artifact will be downloaded, which causes
package conflict. For example, org.apache.commons:commons-io:1.3.2 is
relocated to commons-io:commons-io:1.3.2, if a project depends on
org.apache.commons:commons-io:1.3.2 and commons-io:commons-io:2.4, the
two artifacts will both exist in resolved classpath.
(See MavenPomPackagingResolveIntegrationTest.groovy provided in this
commit) This fix checks if relocation exists in pom and ignore its
artifact if necessary. This problem is first introduced in Gradle 2.0.

An integration test is provide to justify the fix.

In addition, an unnecessary artifact retrieval in test and a redundant
System.out.println("") is removed.
  • Loading branch information
blindpirate committed May 29, 2017
1 parent 301738c commit 190e808
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ public String getDisplayName() {
@Override
public void execute(CallableBuildOperation<T> buildOperation, BuildOperationContext context) {
returnValue = buildOperation.call(context);
System.out.print("");
}

public T getReturnValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,27 @@ compile('group:projectA:1.0') {
succeeds 'retrieve'
}

@Issue('https://github.com/gradle/gradle/issues/1789')
def "ignore artifact when relocation is defined in pom"() {
given:
buildFile << """
repositories { jcenter() }
configurations { compile }
dependencies {
// http://repo1.maven.org/maven2/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.pom
compile 'org.apache.commons:commons-io:1.3.2'
compile 'commons-io:commons-io:2.4'
}
task retrieve(type: Sync) {
from configurations.compile
into 'libs'
}
"""
when:
run 'retrieve'

then:
file("libs").assertHasDescendants("commons-io-2.4.jar")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ task retrieve(type: Sync) {

and:
original.pom.expectGet()
original.artifact.expectHead()
newModule.pom.expectGet()
newModule.artifact.expectGet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.gradle.internal.component.external.model.ModuleComponentArtifactIdentifier;
import org.gradle.internal.component.external.model.ModuleComponentArtifactMetadata;
import org.gradle.internal.component.external.model.MutableMavenModuleResolveMetadata;
import org.gradle.internal.component.model.ComponentArtifactMetadata;
import org.gradle.internal.component.model.ComponentOverrideMetadata;
import org.gradle.internal.component.model.DefaultIvyArtifactName;
import org.gradle.internal.component.model.IvyArtifactName;
Expand Down Expand Up @@ -252,6 +253,8 @@ protected void resolveModuleArtifacts(MavenModuleResolveMetadata module, Buildab
if (module.isKnownJarPackaging()) {
ModuleComponentArtifactMetadata artifact = module.artifact("jar", "jar", null);
result.resolved(new FixedComponentArtifacts(ImmutableSet.of(artifact)));
} else if (module.isRelocated()) {
result.resolved(new FixedComponentArtifacts(Collections.<ComponentArtifactMetadata>emptyList()));
}
}

Expand Down

0 comments on commit 190e808

Please sign in to comment.