Skip to content

Commit

Permalink
detect if dependency is actually the current project. (#736)
Browse files Browse the repository at this point in the history
We filter out artifacts from the current project
  • Loading branch information
esword authored and bulldozer-bot[bot] committed Aug 6, 2019
1 parent 555924d commit 2ec513f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-736.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: "The `checkImplicitDependencies` task will no longer suggest a fix of the current project."
links:
- https://github.com/palantir/gradle-baseline/pull/736
- https://github.com/palantir/gradle-baseline/issues/567
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final void checkImplicitDependencies() {
.map(BaselineExactDependencies.INDEXES::classToDependency)
.filter(Optional::isPresent)
.map(Optional::get)
.filter(x -> !isArtifactFromCurrentProject(x))
.collect(Collectors.toSet());
Set<ResolvedArtifact> declaredArtifacts = declaredDependencies.stream()
.flatMap(dependency -> dependency.getModuleArtifacts().stream())
Expand Down Expand Up @@ -112,6 +113,19 @@ private boolean isProjectArtifact(ResolvedArtifact artifact) {
return artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier;
}

/**
* Return true if the resolved artifact is derived from a project in the current build rather than an
* external jar.
*/
private boolean isArtifactFromCurrentProject(ResolvedArtifact artifact) {
if (!isProjectArtifact(artifact)) {
return false;
}
return ((ProjectComponentIdentifier) artifact.getId().getComponentIdentifier()).getProjectPath()
.equals(getProject().getPath());
}


/** All classes which are mentioned in this project's source code. */
private Set<String> referencedClasses() {
return Streams.stream(sourceClasses.get().iterator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package com.palantir.baseline

import java.nio.file.Files
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome

import java.nio.file.Files

class BaselineExactDependenciesTest extends AbstractPluginTest {

def standardBuildFile = '''
Expand Down Expand Up @@ -125,6 +124,15 @@ class BaselineExactDependenciesTest extends AbstractPluginTest {
result.output.contains("implementation project(':sub-project-no-deps')")
}

def 'checkImplicitDependencies should not report circular dependency on current project'() {
when:
setupMultiProject()

then:
BuildResult result = with(':sub-project-with-deps:checkImplicitDependencies', ':sub-project-no-deps:checkImplicitDependencies', '--stacktrace').withDebug(true).build()
result.task(':sub-project-no-deps:checkImplicitDependencies').getOutcome() == TaskOutcome.SUCCESS
}

/**
* Sets up a multi-module project with 2 sub projects. The root project has a transitive dependency on sub-project-no-deps
* and so checkImplicitDependencies should fail on it.
Expand Down

0 comments on commit 2ec513f

Please sign in to comment.