diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java index 400b2d8171f9f..19b04a48b53c0 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java @@ -149,7 +149,9 @@ public static void configureConfigurations(Project project) { private static final Pattern LUCENE_SNAPSHOT_REGEX = Pattern.compile("\\w+-snapshot-([a-z0-9]+)"); - /** Adds repositories used by ES dependencies */ + /** + * Adds repositories used by ES dependencies + */ public static void configureRepositories(Project project) { // ensure all repositories use secure urls // TODO: remove this with gradle 7.0, which no longer allows insecure urls @@ -216,7 +218,9 @@ private static void assertRepositoryURIIsSecure(final String repositoryName, fin } } - /** Adds compiler settings to the project */ + /** + * Adds compiler settings to the project + */ public static void configureCompile(Project project) { project.getExtensions().getExtraProperties().set("compactProfile", "full"); @@ -483,8 +487,11 @@ static void configureJars(Project project) { // we put all our distributable files under distributions jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions")); // fixup the jar manifest - jarTask.doFirst( - t -> { + // Explicitly using an Action interface as java lambdas + // are not supported by Gradle up-to-date checks + jarTask.doFirst(new Action() { + @Override + public void execute(Task task) { // this doFirst is added before the info plugin, therefore it will run // after the doFirst added by the info plugin, and we can override attributes jarTask.getManifest() @@ -497,7 +504,7 @@ static void configureJars(Project project) { ) ); } - ); + }); } ); project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/CheckstylePrecommitPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/CheckstylePrecommitPlugin.java index 2c6fd329750df..ba937c0245c99 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/CheckstylePrecommitPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/CheckstylePrecommitPlugin.java @@ -21,6 +21,7 @@ import org.elasticsearch.gradle.VersionProperties; import org.elasticsearch.gradle.util.Util; +import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.artifacts.dsl.DependencyHandler; @@ -62,17 +63,22 @@ public TaskProvider createTask(Project project) { copyCheckstyleConf.configure(t -> t.getInputs().files(checkstyleConfUrl.getFile(), checkstyleSuppressionsUrl.getFile())); } - copyCheckstyleConf.configure(t -> t.doLast(task -> { - checkstyleDir.mkdirs(); - try (InputStream stream = checkstyleConfUrl.openStream()) { - Files.copy(stream, checkstyleConf.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - try (InputStream stream = checkstyleSuppressionsUrl.openStream()) { - Files.copy(stream, checkstyleSuppressions.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new UncheckedIOException(e); + // Explicitly using an Action interface as java lambdas + // are not supported by Gradle up-to-date checks + copyCheckstyleConf.configure(t -> t.doLast(new Action() { + @Override + public void execute(Task task) { + checkstyleDir.mkdirs(); + try (InputStream stream = checkstyleConfUrl.openStream()) { + Files.copy(stream, checkstyleConf.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + try (InputStream stream = checkstyleSuppressionsUrl.openStream()) { + Files.copy(stream, checkstyleSuppressions.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } })); diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/DependencyLicensesTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/DependencyLicensesTask.java index 5c7b5e55d86e6..ff1d6186a42ce 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/DependencyLicensesTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/DependencyLicensesTask.java @@ -31,6 +31,7 @@ import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputDirectory; import org.gradle.api.tasks.TaskAction; import java.io.File; @@ -223,6 +224,15 @@ public void checkDependencies() throws IOException, NoSuchAlgorithmException { if (shaFiles.isEmpty() == false) { throw new GradleException("Unused sha files found: \n" + joinFilenames(shaFiles)); } + + } + + // This is just a marker output folder to allow this task being up-to-date. + // The check logic is exception driven so a failed tasks will not be defined + // by this output but when successful we can safely mark the task as up-to-date. + @OutputDirectory + public File getOutputMarker() { + return new File(getProject().getBuildDir(), "dependencyLicense"); } private void failIfAnyMissing(String item, Boolean exists, String type) {