|
@@ -32,9 +32,9 @@ import org.gradle.api.tasks.compile.JavaCompile;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* A wrapper around Gradle's Java Base plugin that applies our
|
|
|
* common configuration for production code.
|
|
@@ -50,6 +50,7 @@ public class ElasticsearchJavaBasePlugin implements Plugin<Project> {
|
|
|
project.getPluginManager().apply(ElasticsearchTestBasePlugin.class);
|
|
|
project.getPluginManager().apply(PrecommitTaskPlugin.class);
|
|
|
|
|
|
+ configureConfigurations(project);
|
|
|
configureCompile(project);
|
|
|
configureInputNormalization(project);
|
|
|
|
|
@@ -57,6 +58,54 @@ public class ElasticsearchJavaBasePlugin implements Plugin<Project> {
|
|
|
project.getExtensions().getExtraProperties().set("versions", VersionProperties.getVersions());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Makes dependencies non-transitive.
|
|
|
+ * <p>
|
|
|
+ * Gradle allows setting all dependencies as non-transitive very easily.
|
|
|
+ * Sadly this mechanism does not translate into maven pom generation. In order
|
|
|
+ * to effectively make the pom act as if it has no transitive dependencies,
|
|
|
+ * we must exclude each transitive dependency of each direct dependency.
|
|
|
+ * <p>
|
|
|
+ * Determining the transitive deps of a dependency which has been resolved as
|
|
|
+ * non-transitive is difficult because the process of resolving removes the
|
|
|
+ * transitive deps. To sidestep this issue, we create a configuration per
|
|
|
+ * direct dependency version. This specially named and unique configuration
|
|
|
+ * will contain all of the transitive dependencies of this particular
|
|
|
+ * dependency. We can then use this configuration during pom generation
|
|
|
+ * to iterate the transitive dependencies and add excludes.
|
|
|
+ */
|
|
|
+ public static void configureConfigurations(Project project) {
|
|
|
+ // we are not shipping these jars, we act like dumb consumers of these things
|
|
|
+ if (project.getPath().startsWith(":test:fixtures") || project.getPath().equals(":build-tools")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // fail on any conflicting dependency versions
|
|
|
+ project.getConfigurations().all(configuration -> {
|
|
|
+ if (configuration.getName().endsWith("Fixture")) {
|
|
|
+ // just a self contained test-fixture configuration, likely transitive and hellacious
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ configuration.resolutionStrategy(ResolutionStrategy::failOnVersionConflict);
|
|
|
+ });
|
|
|
+
|
|
|
+ // disable transitive dependency management
|
|
|
+ SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
|
|
|
+ sourceSets.all(sourceSet -> disableTransitiveDependenciesForSourceSet(project, sourceSet));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void disableTransitiveDependenciesForSourceSet(Project project, SourceSet sourceSet) {
|
|
|
+ List<String> sourceSetConfigurationNames = List.of(
|
|
|
+ sourceSet.getApiConfigurationName(),
|
|
|
+ sourceSet.getImplementationConfigurationName(),
|
|
|
+ sourceSet.getImplementationConfigurationName(),
|
|
|
+ sourceSet.getCompileOnlyConfigurationName(),
|
|
|
+ sourceSet.getRuntimeOnlyConfigurationName()
|
|
|
+ );
|
|
|
+
|
|
|
+ project.getConfigurations().matching(c -> sourceSetConfigurationNames.contains(c.getName()))
|
|
|
+ .configureEach(GradleUtils::disableTransitiveDependencies);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Adds compiler settings to the project
|
|
|
*/
|
|
@@ -90,13 +139,16 @@ public class ElasticsearchJavaBasePlugin implements Plugin<Project> {
|
|
|
compileOptions.getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask));
|
|
|
});
|
|
|
// also apply release flag to groovy, which is used in build-tools
|
|
|
- project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> {
|
|
|
- // TODO: this probably shouldn't apply to groovy at all?
|
|
|
- compileTask.getOptions().getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask));
|
|
|
- });
|
|
|
+ project.getTasks()
|
|
|
+ .withType(GroovyCompile.class)
|
|
|
+ .configureEach(
|
|
|
+ compileTask -> {
|
|
|
+ // TODO: this probably shouldn't apply to groovy at all?
|
|
|
+ compileTask.getOptions().getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Apply runtime classpath input normalization so that changes in JAR manifests don't break build cacheability
|
|
|
*/
|