Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back checkUnusedDependencies.ignore and checkImplicitDependencies.ignore #1273

Merged
merged 8 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-1273.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Bring back the `ignore(String, String)` method on the `checkUnusedDependencies` and
`checkImplicitDependencies` tasks. This now ignores the coordinate for all source
sets.
links:
- https://github.com/palantir/gradle-baseline/pull/1273
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.palantir.baseline.tasks.CheckImplicitDependenciesParentTask;
import com.palantir.baseline.tasks.CheckImplicitDependenciesTask;
import com.palantir.baseline.tasks.CheckUnusedDependenciesParentTask;
import com.palantir.baseline.tasks.CheckUnusedDependenciesTask;
import java.io.File;
import java.io.IOException;
Expand All @@ -38,7 +40,6 @@
import org.apache.maven.shared.dependency.analyzer.asm.ASMDependencyAnalyzer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExcludeRule;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
Expand Down Expand Up @@ -67,8 +68,10 @@ public final class BaselineExactDependencies implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getPluginManager().withPlugin("java", plugin -> {
TaskProvider<Task> checkUnusedDependencies = project.getTasks().register("checkUnusedDependencies");
TaskProvider<Task> checkImplicitDependencies = project.getTasks().register("checkImplicitDependencies");
TaskProvider<CheckUnusedDependenciesParentTask> checkUnusedDependencies =
project.getTasks().register("checkUnusedDependencies", CheckUnusedDependenciesParentTask.class);
TaskProvider<CheckImplicitDependenciesParentTask> checkImplicitDependencies =
project.getTasks().register("checkImplicitDependencies", CheckImplicitDependenciesParentTask.class);

project.getConvention()
.getPlugin(JavaPluginConvention.class)
Expand All @@ -81,8 +84,8 @@ public void apply(Project project) {
private static void configureSourceSet(
Project project,
SourceSet sourceSet,
TaskProvider<Task> checkUnusedDependencies,
TaskProvider<Task> checkImplicitDependencies) {
TaskProvider<CheckUnusedDependenciesParentTask> checkUnusedDependencies,
TaskProvider<CheckImplicitDependenciesParentTask> checkImplicitDependencies) {
Configuration implementation =
project.getConfigurations().getByName(sourceSet.getImplementationConfigurationName());
Configuration compile = project.getConfigurations().getByName(sourceSet.getCompileConfigurationName());
Expand Down Expand Up @@ -156,6 +159,9 @@ private static void configureSourceSet(

// this is liberally applied to ease the Java8 -> 11 transition
task.ignore("javax.annotation", "javax.annotation-api");

// pick up ignores configured globally on the parent task
task.ignore(checkUnusedDependencies.get().getIgnore());
});
checkUnusedDependencies.configure(task -> task.dependsOn(sourceSetUnusedDependencies));
TaskProvider<CheckImplicitDependenciesTask> sourceSetCheckImplicitDependencies = project.getTasks()
Expand All @@ -168,6 +174,9 @@ private static void configureSourceSet(
task.dependenciesConfiguration(compileClasspath);

task.ignore("org.slf4j", "slf4j-api");

// pick up ignores configured globally on the parent task
task.ignore(checkImplicitDependencies.get().getIgnore());
});
checkImplicitDependencies.configure(task -> task.dependsOn(sourceSetCheckImplicitDependencies));
}
Expand Down Expand Up @@ -281,4 +290,8 @@ public ResolvedDependency artifactsFromDependency(ResolvedArtifact resolvedArtif
artifactsFromDependency.get(resolvedArtifact), "Unable to find resolved artifact");
}
}

public static String ignoreCoordinate(String group, String name) {
return group + ":" + name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline.tasks;

import com.palantir.baseline.plugins.BaselineExactDependencies;
import java.util.Collections;
import java.util.Set;
import org.gradle.api.DefaultTask;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.Internal;

public class CheckImplicitDependenciesParentTask extends DefaultTask {
private final SetProperty<String> ignore;

public CheckImplicitDependenciesParentTask() {
ignore = getProject().getObjects().setProperty(String.class);
ignore.set(Collections.emptySet());
}

/** Ignores these coordinates for all source sets. */
public final void ignore(Provider<Set<String>> value) {
ignore.addAll(value);
}

/** Ignores this coordinate for all source sets. */
public final void ignore(String group, String name) {
ignore.add(BaselineExactDependencies.ignoreCoordinate(group, name));
}

@Internal
public final Provider<Set<String>> getIgnore() {
return ignore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public final void ignore(Provider<Set<String>> value) {
}

public final void ignore(String group, String name) {
ignore.add(group + ":" + name);
ignore.add(BaselineExactDependencies.ignoreCoordinate(group, name));
}

@Input
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline.tasks;

import com.palantir.baseline.plugins.BaselineExactDependencies;
import java.util.Collections;
import java.util.Set;
import org.gradle.api.DefaultTask;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.Internal;

public class CheckUnusedDependenciesParentTask extends DefaultTask {
private final SetProperty<String> ignore;

public CheckUnusedDependenciesParentTask() {
ignore = getProject().getObjects().setProperty(String.class);
ignore.set(Collections.emptySet());
}

/** Ignores these coordinates for all source sets. */
public final void ignore(Provider<Set<String>> value) {
ignore.addAll(value);
}

/** Ignores this coordinate for all source sets. */
public final void ignore(String group, String name) {
ignore.add(BaselineExactDependencies.ignoreCoordinate(group, name));
}

@Internal
public final Provider<Set<String>> getIgnore() {
return ignore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public final void checkUnusedDependencies() {
}

/**
* Excludes compileOnly and annotationProcessor dependencies as they would be incorrectly flagged as unused by this
* task due to BaselineExactDependencies use of
* Excludes any source only dependencies configured by the user, as they would be incorrectly flagged as unused by
* this task due to BaselineExactDependencies use of
* {@link org.apache.maven.shared.dependency.analyzer.asm.ASMDependencyAnalyzer} which only looks at the
* dependencies of the generated byte-code, not the union of compile + runtime dependencies.
*/
Expand Down Expand Up @@ -190,6 +190,13 @@ public final Provider<List<Configuration>> getSourceOnlyConfigurations() {
return sourceOnlyConfigurations;
}

/**
* Don't use this unless this configuration is resolvable.
*
* @deprecated This task only looks at <em>directly declared</em> compile dependencies that also appear in the
* runtime classpath, so there's no need to exclude anything like {@code compileOnly} anymore.
*/
@Deprecated
public final void sourceOnlyConfiguration(Configuration configuration) {
Preconditions.checkNotNull(configuration, "This method requires a non-null configuration");
Preconditions.checkArgument(
Expand All @@ -209,11 +216,11 @@ public final void setSourceClasses(FileCollection newClasses) {
}

public final void ignore(Provider<Set<String>> value) {
ignore.set(value);
ignore.addAll(value);
}

public final void ignore(String group, String name) {
ignore.add(group + ":" + name);
ignore.add(BaselineExactDependencies.ignoreCoordinate(group, name));
}

@Input
Expand Down