Skip to content

Commit

Permalink
Fix: classpath uniqueness checks runtimeClasspath by default (#810)
Browse files Browse the repository at this point in the history
ClassUniquenessPlugin now checks the `runtimeClasspath` configuration by default.
  • Loading branch information
dansanduleac authored and bulldozer-bot[bot] committed Sep 11, 2019
1 parent 286e153 commit 7f6540b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-810.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: ClassUniquenessPlugin now checks the `runtimeClasspath` configuration
by default.
links:
- https://github.com/palantir/gradle-baseline/pull/810
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public final void apply(Project project) {
project.getTasks().addRule(rule);

project.getPlugins().withId("java", plugin -> {
rule.apply("checkRuntimeClassUniqueness");
String checkRuntimeClasspathTask = "checkRuntimeClasspathClassUniqueness";
rule.apply(checkRuntimeClasspathTask);
project.getTasks().getByName("check")
.dependsOn(project.getTasks().getByName("checkRuntimeClassUniqueness"));
.dependsOn(project.getTasks().getByName(checkRuntimeClasspathTask));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {

then:
def result = with('check', '--stacktrace').build()
result.task(':checkRuntimeClassUniqueness').outcome == TaskOutcome.SUCCESS
result.task(':checkRuntimeClasspathClassUniqueness').outcome == TaskOutcome.SUCCESS
}

def 'detect duplicates in two external jars'() {
Expand All @@ -55,11 +55,11 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
}
""".stripIndent()
BuildResult result = with('checkRuntimeClassUniqueness').buildAndFail()
BuildResult result = with('checkRuntimeClasspathClassUniqueness').buildAndFail()

then:
result.output.contains("26 Identically named classes with differing impls found in [javax.servlet.jsp:jsp-api:2.1, javax.el:javax.el-api:3.0.0]: [javax.")
result.getOutput().contains("'runtime' contains multiple copies of identically named classes")
result.getOutput().contains("'runtimeClasspath' contains multiple copies of identically named classes")
result.getOutput().contains("(26 classes) javax.servlet.jsp:jsp-api:2.1 javax.el:javax.el-api:3.0.0");
println result.getOutput()
}
Expand All @@ -75,6 +75,8 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
myConf group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
myConf group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
}
""".stripIndent()
BuildResult result = with('checkMyConfClassUniqueness').buildAndFail()

Expand All @@ -97,19 +99,19 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
""".stripIndent()

then:
with('checkRuntimeClassUniqueness').build()
with('checkRuntimeClasspathClassUniqueness').build()
}

def 'task should be up-to-date when classpath is unchanged'() {
when:
buildFile << standardBuildFile

then:
BuildResult result1 = with('checkRuntimeClassUniqueness').build()
result1.task(':checkRuntimeClassUniqueness').outcome == TaskOutcome.SUCCESS
BuildResult result1 = with('checkRuntimeClasspathClassUniqueness').build()
result1.task(':checkRuntimeClasspathClassUniqueness').outcome == TaskOutcome.SUCCESS

BuildResult result = with('checkRuntimeClassUniqueness').build()
result.task(':checkRuntimeClassUniqueness').outcome == TaskOutcome.UP_TO_DATE
BuildResult result = with('checkRuntimeClasspathClassUniqueness').build()
result.task(':checkRuntimeClasspathClassUniqueness').outcome == TaskOutcome.UP_TO_DATE
}

def 'passes when no duplicates are present'() {
Expand All @@ -123,10 +125,10 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
compile 'com.netflix.nebula:nebula-test:6.4.2'
}
""".stripIndent()
BuildResult result = with('checkRuntimeClassUniqueness', '--info').build()
BuildResult result = with('checkRuntimeClasspathClassUniqueness', '--info').build()

then:
result.task(":checkRuntimeClassUniqueness").outcome == TaskOutcome.SUCCESS
result.task(":checkRuntimeClasspathClassUniqueness").outcome == TaskOutcome.SUCCESS
println result.getOutput()
}

Expand All @@ -152,7 +154,7 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
""".stripIndent()

then:
BuildResult result = with('checkRuntimeClassUniqueness').buildAndFail()
BuildResult result = with('checkRuntimeClasspathClassUniqueness').buildAndFail()
result.output.contains("26 Identically named classes with differing impls found in [javax.servlet.jsp:jsp-api:2.1, javax.el:javax.el-api:3.0.0]: [javax.")
}

Expand All @@ -173,8 +175,8 @@ class BaselineClassUniquenessPluginIntegrationTest extends AbstractPluginTest {
""".stripIndent()

then:
BuildResult result = with('checkRuntimeClassUniqueness', '--info').build()
BuildResult result = with('checkRuntimeClasspathClassUniqueness', '--info').build()
println result.getOutput()
result.task(":checkRuntimeClassUniqueness").outcome == TaskOutcome.SUCCESS // ideally should should say failed!
result.task(":checkRuntimeClasspathClassUniqueness").outcome == TaskOutcome.SUCCESS // ideally should should say failed!
}
}

0 comments on commit 7f6540b

Please sign in to comment.